Fixed graph precision

This commit is contained in:
danielmaya 2018-02-28 14:33:22 +01:00
parent 99d5da9dd3
commit 9d36887a02
5 changed files with 41 additions and 27 deletions

View File

@ -0,0 +1,13 @@
START TRANSACTION;
SET @st_oum720 = (SELECT IF(
(SELECT value FROM tconfig WHERE token like 'short_module_graph_data') = 1,
"UPDATE tconfig SET value = 2 WHERE token LIKE 'short_module_graph_data'",
"UPDATE tconfig SET value = '' WHERE token LIKE 'short_module_graph_data'"
));
PREPARE pr_oum720 FROM @st_oum720;
EXECUTE pr_oum720;
DEALLOCATE PREPARE pr_oum720;
COMMIT;

View File

@ -487,11 +487,18 @@ if (!enterprise_installed()) {
$disabled_graph_precision = true;
}
$table_chars->data[$row][0] = __('Data precision for reports and visual consoles');
$table_chars->data[$row][0] .= ui_print_help_tip(__('Number of decimals shown in reports and visual consoles. It must be a number between 0 and 5'), true);
$table_chars->data[$row][0] = __('Data precision in PandoraFMS');
$table_chars->data[$row][0] .= ui_print_help_tip(__('Number of decimals shown. It must be a number between 0 and 5, except in graphs.'), true);
$table_chars->data[$row][1] = html_print_input_text ('graph_precision', $config["graph_precision"], '', 5, 5, true, $disabled_graph_precision, false, "onChange=\"change_precision()\"");
$row++;
if (!isset($config["short_module_graph_data"]))
$config["short_module_graph_data"] = true;
$table_chars->data[$row][0] = __('Data precision in graphs');
$table_chars->data[$row][0] .= ui_print_help_tip(__('Number of decimals shown. If the field is empty, it will show all the decimals'), true);
$table_chars->data[$row][1] = html_print_input_text ('short_module_graph_data', $config["short_module_graph_data"], '', 5, 5, true, $disabled_graph_precision, false, "onChange=\"change_precision()\"");
$row++;
$table_chars->data[$row][0] = __('Default line thickness for the Custom Graph.');
$table_chars->data[$row][1] = html_print_input_text ('custom_graph_width',
$config["custom_graph_width"], '', 5, 5, true);
@ -510,18 +517,6 @@ $table_chars->data[$row][1] .= __('No').' ' .
html_print_radio_button ('flash_charts', 0, '', $config["global_flash_charts"], true);
$row++;
if (!isset($config["short_module_graph_data"]))
$config["short_module_graph_data"] = true;
$table_chars->data[$row][0] = __('Shortened module graph data');
$table_chars->data[$row][0] .= ui_print_help_tip(__('The data number of the module graphs will be rounded and shortened'), true);
$table_chars->data[$row][1] = __('Yes') . ' ' .
html_print_radio_button ('short_module_graph_data', 1, '',
$config["short_module_graph_data"], true) .
'  ';
$table_chars->data[$row][1] .= __('No') . ' ' .
html_print_radio_button ('short_module_graph_data', 0, '',
$config["short_module_graph_data"], true);
$row++;
$table_chars->data[$row][0] = __('Type of module charts');
$table_chars->data[$row][1] = __('Area').' ' .

View File

@ -1864,6 +1864,10 @@ function config_process_config () {
config_update_value ('networkmap_max_width', 900);
}
if (!isset($config['short_module_graph_data'])) {
config_update_value ('short_module_graph_data', '');
}
if (!isset($config['tutorial_mode'])) {
config_update_value ('tutorial_mode', 'full');
}

View File

@ -1773,7 +1773,7 @@ function pandoraFlotArea(graph_id, values, labels, labels_long, legend,
$('#timestamp_'+graph_id).show();
// If no legend, the timestamp labels are short and with value
if (legend.length == 0) {
$('#timestamp_'+graph_id).text(labels[j] + ' (' + (short_data ? parseFloat(y).toFixed(2) : parseFloat(y)) + ')');
$('#timestamp_'+graph_id).text(labels[j] + ' (' + (short_data ? number_format(y, 0, "", short_data) : parseFloat(y)) + ')');
}
else {
$('#timestamp_'+graph_id).text(labels_long[j]);
@ -1809,7 +1809,7 @@ function pandoraFlotArea(graph_id, values, labels, labels_long, legend,
// The graphs of points type and unknown graphs will dont be updated
if (serie_types[i] != 'points' && series.label != $('#hidden-unknown_text').val()) {
$('#legend_' + graph_id + ' .legendLabel')
.eq(i).html(label_aux + '= ' + (short_data ? parseFloat(y).toFixed(2) : parseFloat(y)) + how_bigger + ' ' + unit);
.eq(i).html(label_aux + '= ' + (short_data ? number_format(y, 0, "", short_data) : parseFloat(y)) + how_bigger + ' ' + unit);
}
$('#legend_' + graph_id + ' .legendLabel')
@ -1925,7 +1925,7 @@ function pandoraFlotArea(graph_id, values, labels, labels_long, legend,
function yFormatter(v, axis) {
axis.datamin = 0;
if (short_data) {
var formatted = number_format(v, force_integer, "");
var formatted = number_format(v, force_integer, "", short_data);
}
else {
var formatted = v;
@ -2177,15 +2177,16 @@ function check_adaptions(graph_id) {
});
}
function number_format(number, force_integer, unit) {
function number_format(number, force_integer, unit, short_data) {
if (force_integer) {
if (Math.round(number) != number) {
return '';
}
}
else {
// Round to 2 decimals
number = Math.round(number * 100) / 100;
short_data ++;
decimals = pad(1, short_data, 0);
number = Math.round(number * decimals) / decimals;
}
var shorts = ["", "K", "M", "G", "T", "P", "E", "Z", "Y"];
@ -2206,6 +2207,11 @@ function number_format(number, force_integer, unit) {
return number + ' ' + shorts[pos] + unit;
}
function pad(input, length, padding) {
var str = input + "";
return (length <= str.length) ? str : pad(str+padding, length, padding);
}
// Recalculate the threshold data depends on warning and critical
function axis_thresholded (threshold_data, y_min, y_max, red_threshold, extremes, red_up) {

View File

@ -490,14 +490,10 @@ function flot_area_graph($chart_data, $width, $height, $color, $legend,
true);
if (!isset($config["short_module_graph_data"]))
$config["short_module_graph_data"] = true;
$config["short_module_graph_data"] = '';
if ($config["short_module_graph_data"]) {
$short_data = true;
}
else {
$short_data = false;
}
$short_data = $config["short_module_graph_data"];
// Javascript code