Fixed lower than 1 values on gauges

This commit is contained in:
fermin831 2017-10-25 18:40:58 +02:00
parent 8fa33a2401
commit 7379243946
1 changed files with 17 additions and 9 deletions

View File

@ -1037,18 +1037,18 @@ function createGauges(data, width, height, font_size, no_data_image, font) {
label = label.replace(/(/g,'\('); label = label.replace(/(/g,'\(');
label = label.replace(/)/g,'\)'); label = label.replace(/)/g,'\)');
minimun_warning = Math.round(parseFloat( data[key].min_warning ),2); minimun_warning = round_with_decimals(parseFloat( data[key].min_warning ));
maximun_warning = Math.round(parseFloat( data[key].max_warning ),2); maximun_warning = round_with_decimals(parseFloat( data[key].max_warning ));
minimun_critical = Math.round(parseFloat( data[key].min_critical ),2); minimun_critical = round_with_decimals(parseFloat( data[key].min_critical ));
maximun_critical = Math.round(parseFloat( data[key].max_critical ),2); maximun_critical = round_with_decimals(parseFloat( data[key].max_critical ));
mininum = Math.round(parseFloat(data[key].min),2); mininum = round_with_decimals(parseFloat(data[key].min));
maxinum = Math.round(parseFloat(data[key].max),2); maxinum = round_with_decimals(parseFloat(data[key].max));
critical_inverse = parseInt(data[key].critical_inverse); critical_inverse = parseInt(data[key].critical_inverse);
warning_inverse = parseInt(data[key].warning_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)) if (isNaN(valor))
valor = null; valor = null;
@ -1281,7 +1281,7 @@ function Gauge(placeholderName, configuration, font)
{ {
var pointerContainer = this.body.select(".pointerContainer"); 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"); var pointer = pointerContainer.selectAll("path");
pointer.transition() pointer.transition()
@ -1493,3 +1493,11 @@ function print_phases_donut (recipient, phases) {
.remove(); .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);
}