Minor changes to allow hbar min/max ranges

This commit is contained in:
fbsanchez 2017-11-08 16:41:23 +01:00
parent cd508098cb
commit a42a2ee7e2
3 changed files with 24 additions and 7 deletions

View File

@ -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 {

View File

@ -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 );

View File

@ -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 .= "<script type='text/javascript'>";
$return .= "pandoraFlotHBars('$graph_id', '$values', '$labels',
false, $max, '$water_mark', '$separator', '$separator2', '$font', $font_size, '$background_color')";
false, $max, '$water_mark', '$separator', '$separator2', '$font', $font_size, '$background_color', $val_min, $val_max)";
$return .= "</script>";