From 7379243946fd85c50eb854547caa3dcb9db56905 Mon Sep 17 00:00:00 2001 From: fermin831 Date: Wed, 25 Oct 2017 18:40:58 +0200 Subject: [PATCH] Fixed lower than 1 values on gauges --- pandora_console/include/graphs/pandora.d3.js | 26 +++++++++++++------- 1 file changed, 17 insertions(+), 9 deletions(-) diff --git a/pandora_console/include/graphs/pandora.d3.js b/pandora_console/include/graphs/pandora.d3.js index 95a914104f..79dfceb21d 100644 --- a/pandora_console/include/graphs/pandora.d3.js +++ b/pandora_console/include/graphs/pandora.d3.js @@ -1037,19 +1037,19 @@ function createGauges(data, width, height, font_size, no_data_image, font) { label = label.replace(/(/g,'\('); label = label.replace(/)/g,'\)'); - minimun_warning = Math.round(parseFloat( data[key].min_warning ),2); - maximun_warning = Math.round(parseFloat( data[key].max_warning ),2); - minimun_critical = Math.round(parseFloat( data[key].min_critical ),2); - maximun_critical = Math.round(parseFloat( data[key].max_critical ),2); + minimun_warning = round_with_decimals(parseFloat( data[key].min_warning )); + maximun_warning = round_with_decimals(parseFloat( data[key].max_warning )); + minimun_critical = round_with_decimals(parseFloat( data[key].min_critical )); + maximun_critical = round_with_decimals(parseFloat( data[key].max_critical )); - mininum = Math.round(parseFloat(data[key].min),2); - maxinum = Math.round(parseFloat(data[key].max),2); + mininum = round_with_decimals(parseFloat(data[key].min)); + maxinum = round_with_decimals(parseFloat(data[key].max)); critical_inverse = parseInt(data[key].critical_inverse); warning_inverse = parseInt(data[key].warning_inverse); - valor = Math.round(parseFloat(data[key].value),2); - + valor = round_with_decimals(data[key].value); + if (isNaN(valor)) valor = null; createGauge(nombre, label, valor, mininum, maxinum, @@ -1281,7 +1281,7 @@ function Gauge(placeholderName, configuration, font) { var pointerContainer = this.body.select(".pointerContainer"); - pointerContainer.selectAll("text").text(Math.round(value)); + pointerContainer.selectAll("text").text(round_with_decimals(value)); var pointer = pointerContainer.selectAll("path"); pointer.transition() @@ -1492,4 +1492,12 @@ function print_phases_donut (recipient, phases) { polyline.exit() .remove(); } +} + +function round_with_decimals (value, multiplier = 1) { + if ((value * multiplier) == 0) return 0; + if ((value * multiplier) >= 1) { + return Math.round(value * multiplier) / multiplier; + } + return round_with_decimals (value, multiplier * 10); } \ No newline at end of file