From a42a2ee7e2c61a646dac3906db9c315c94687f6c Mon Sep 17 00:00:00 2001 From: fbsanchez Date: Wed, 8 Nov 2017 16:41:23 +0100 Subject: [PATCH] Minor changes to allow hbar min/max ranges --- pandora_console/include/graphs/fgraph.php | 4 ++-- .../include/graphs/flot/pandora.flot.js | 10 ++++++++-- .../include/graphs/functions_flot.php | 17 ++++++++++++++--- 3 files changed, 24 insertions(+), 7 deletions(-) diff --git a/pandora_console/include/graphs/fgraph.php b/pandora_console/include/graphs/fgraph.php index 74a2ea251d..bee7ad4e48 100644 --- a/pandora_console/include/graphs/fgraph.php +++ b/pandora_console/include/graphs/fgraph.php @@ -642,7 +642,7 @@ function polar_graph($flash_chart, $chart_data, $width, $height, function hbar_graph($flash_chart, $chart_data, $width, $height, $color, $legend, $long_index, $no_data_image, $xaxisname = "", $yaxisname = "", $water_mark = "", $font = '', $font_size = '', - $unit = '', $ttl = 1, $homeurl = '', $backgroundColor = 'white') { + $unit = '', $ttl = 1, $homeurl = '', $backgroundColor = 'white', $val_min=null, $val_max=null) { setup_watermark($water_mark, $water_mark_file, $water_mark_url); @@ -652,7 +652,7 @@ function hbar_graph($flash_chart, $chart_data, $width, $height, if ($flash_chart) { return flot_hcolumn_chart( - $chart_data, $width, $height, $water_mark_url, $font, $font_size, $backgroundColor); + $chart_data, $width, $height, $water_mark_url, $font, $font_size, $backgroundColor, $val_min, $val_max); } else { diff --git a/pandora_console/include/graphs/flot/pandora.flot.js b/pandora_console/include/graphs/flot/pandora.flot.js index 10b98be29b..86ccc396f2 100644 --- a/pandora_console/include/graphs/flot/pandora.flot.js +++ b/pandora_console/include/graphs/flot/pandora.flot.js @@ -326,7 +326,7 @@ function pandoraFlotPieCustom(graph_id, values, labels, width, } function pandoraFlotHBars(graph_id, values, labels, water_mark, - maxvalue, water_mark, separator, separator2, font, font_size, background_color) { + maxvalue, water_mark, separator, separator2, font, font_size, background_color, min, max) { var colors_data = ['#FC4444','#FFA631','#FAD403','#5BB6E5','#F2919D','#80BA27']; values = values.split(separator2); @@ -401,7 +401,13 @@ function pandoraFlotHBars(graph_id, values, labels, water_mark, // with all 0 values. options['yaxis']['tickDecimals'] = 0; } - + + if (max) { + options['xaxis']['max'] = max; + } + if (min) { + options['xaxis']['min'] = min; + } var plot = $.plot($('#' + graph_id), datas, options ); diff --git a/pandora_console/include/graphs/functions_flot.php b/pandora_console/include/graphs/functions_flot.php index 58b193b0e7..da53e04fc2 100644 --- a/pandora_console/include/graphs/functions_flot.php +++ b/pandora_console/include/graphs/functions_flot.php @@ -674,7 +674,7 @@ function flot_custom_pie_chart ($flash_charts, $graph_values, } // Returns a 3D column chart -function flot_hcolumn_chart ($graph_data, $width, $height, $water_mark, $font = '', $font_size = 7, $background_color = "white") { +function flot_hcolumn_chart ($graph_data, $width, $height, $water_mark, $font = '', $font_size = 7, $background_color = "white", $val_min=null, $val_max=null) { global $config; include_javascript_dependencies_flot_graph(); @@ -710,7 +710,8 @@ function flot_hcolumn_chart ($graph_data, $width, $height, $water_mark, $font = $a = array(); $vars = array(); - $max = 0; + $max = PHP_INT_MIN+1; + $min = PHP_INT_MAX-1; $i = count($graph_data); $data = array(); @@ -727,9 +728,19 @@ function flot_hcolumn_chart ($graph_data, $width, $height, $water_mark, $font = if ($value > $max) { $max = $value; } + + if ($value < $min) { + $min = $value; + } } } + if (!is_numeric($val_min)) { + $val_min = $min; + } + if (!is_numeric($val_max)) { + $val_max = $max; + } // Store serialized data to use it from javascript $labels = implode($separator,$labels); @@ -755,7 +766,7 @@ function flot_hcolumn_chart ($graph_data, $width, $height, $water_mark, $font = $return .= "";