From 60551c334b79285364ada456e9f7cfb9de5810eb Mon Sep 17 00:00:00 2001 From: Jordi Sanfeliu Date: Tue, 3 Feb 2015 16:11:04 +0100 Subject: [PATCH] Zoomed graphs in 'icecast.pm' now honour the 'global_zoom' option, and they also use the function RRDs::graphv to fit better in the browser pop up window (only for RRDtool v1.3+) --- lib/icecast.pm | 38 ++++++++++++++++++++++++++++++++------ 1 file changed, 32 insertions(+), 6 deletions(-) diff --git a/lib/icecast.pm b/lib/icecast.pm index b019f61..c9115a6 100644 --- a/lib/icecast.pm +++ b/lib/icecast.pm @@ -228,6 +228,15 @@ sub icecast_cgi { my $graph = $cgi->{graph}; my $silent = $cgi->{silent}; my $zoom = "--zoom=" . $config->{global_zoom}; + my %rrd = ( + 'new' => \&RRDs::graphv, + 'old' => \&RRDs::graph, + ); + my $version = "new"; + my $pic; + my $picz; + my $picz_width; + my $picz_height; my $u = ""; my $width; @@ -266,6 +275,7 @@ sub icecast_cgi { "#444444", ); + $version = "old" if $RRDs::VERSION < 1.3; my $rrd = $config->{base_lib} . $package . ".rrd"; my $title = $config->{graph_title}->{$package}; my $PNG_DIR = $config->{base_dir} . "/" . $config->{imgs_dir}; @@ -425,7 +435,7 @@ sub icecast_cgi { push(@CDEF, "CDEF:wrongdata=allvalues,UN,INF,UNKN,IF"); } ($width, $height) = split('x', $config->{graph_size}->{medium}); - RRDs::graph("$PNG_DIR" . "$PNG[$e * 2]", + $pic = $rrd{$version}->("$PNG_DIR" . "$PNG[$e * 2]", "--title=$config->{graphs}->{_icecast1} ($tf->{nwhen}$tf->{twhen})", "--start=-$tf->{nwhen}$tf->{twhen}", "--imgformat=PNG", @@ -452,7 +462,7 @@ sub icecast_cgi { print("ERROR: while graphing $PNG_DIR" . "$PNG[$e * 2]: $err\n") if $err; if(lc($config->{enable_zoom}) eq "y") { ($width, $height) = split('x', $config->{graph_size}->{zoom}); - RRDs::graph("$PNG_DIR" . "$PNGz[$e * 2]", + $picz = $rrd{$version}->("$PNG_DIR" . "$PNGz[$e * 2]", "--title=$config->{graphs}->{_icecast1} ($tf->{nwhen}$tf->{twhen})", "--start=-$tf->{nwhen}$tf->{twhen}", "--imgformat=PNG", @@ -460,6 +470,7 @@ sub icecast_cgi { "--width=$width", "--height=$height", @riglim, + $zoom, @{$cgi->{version12}}, @{$colors->{graph_colors}}, "DEF:ice" . $e . "_mp0=$rrd:icecast" . $e . "_mp0_ls:AVERAGE", @@ -483,7 +494,14 @@ sub icecast_cgi { print(" {url} . "/" . $config->{imgs_dir} . $PNGz[$e * 2] . "\">\n"); } else { - print(" {url} . "/" . $config->{imgs_dir} . $PNGz[$e * 2] . "','','width=" . ($width + 115) . ",height=" . ($height + 100) . ",scrollbars=0,resizable=0'))\">\n"); + if($version eq "new") { + $picz_width = $picz->{image_width} * $config->{global_zoom}; + $picz_height = $picz->{image_height} * $config->{global_zoom}; + } else { + $picz_width = $width + 115; + $picz_height = $height + 100; + } + print(" {url} . "/" . $config->{imgs_dir} . $PNGz[$e * 2] . "','','width=" . $picz_width . ",height=" . $picz_height . ",scrollbars=0,resizable=0'))\">\n"); } } else { print(" \n"); @@ -519,7 +537,7 @@ sub icecast_cgi { push(@CDEF, "CDEF:wrongdata=allvalues,UN,INF,UNKN,IF"); } ($width, $height) = split('x', $config->{graph_size}->{medium}); - RRDs::graph("$PNG_DIR" . $PNG[$e * 2 + 1], + $pic = $rrd{$version}->("$PNG_DIR" . $PNG[$e * 2 + 1], "--title=$config->{graphs}->{_icecast2} ($tf->{nwhen}$tf->{twhen})", "--start=-$tf->{nwhen}$tf->{twhen}", "--imgformat=PNG", @@ -546,7 +564,7 @@ sub icecast_cgi { print("ERROR: while graphing $PNG_DIR" . $PNG[$e * 2 + 1] . ": $err\n") if $err; if(lc($config->{enable_zoom}) eq "y") { ($width, $height) = split('x', $config->{graph_size}->{zoom}); - RRDs::graph("$PNG_DIR" . $PNGz[$e * 2 + 1], + $picz = $rrd{$version}->("$PNG_DIR" . $PNGz[$e * 2 + 1], "--title=$config->{graphs}->{_icecast2} ($tf->{nwhen}$tf->{twhen})", "--start=-$tf->{nwhen}$tf->{twhen}", "--imgformat=PNG", @@ -554,6 +572,7 @@ sub icecast_cgi { "--width=$width", "--height=$height", @riglim, + $zoom, @{$cgi->{version12}}, @{$colors->{graph_colors}}, "DEF:ice" . $e . "_mp0=$rrd:icecast" . $e . "_mp0_br:AVERAGE", @@ -577,7 +596,14 @@ sub icecast_cgi { print(" {url} . "/" . $config->{imgs_dir} . $PNGz[$e * 2 + 1] . "\">\n"); } else { - print(" {url} . "/" . $config->{imgs_dir} . $PNGz[$e * 2 + 1] . "','','width=" . ($width + 115) . ",height=" . ($height + 100) . ",scrollbars=0,resizable=0'))\">\n"); + if($version eq "new") { + $picz_width = $picz->{image_width} * $config->{global_zoom}; + $picz_height = $picz->{image_height} * $config->{global_zoom}; + } else { + $picz_width = $width + 115; + $picz_height = $height + 100; + } + print(" {url} . "/" . $config->{imgs_dir} . $PNGz[$e * 2 + 1] . "','','width=" . $picz_width . ",height=" . $picz_height . ",scrollbars=0,resizable=0'))\">\n"); } } else { print(" \n");