From e8c47dc8995a647b5e569a1dbcc95e399720e78d Mon Sep 17 00:00:00 2001 From: Steffen Vogel Date: Fri, 25 Feb 2011 21:32:04 +0100 Subject: [PATCH] fixed #44 (allows negative values for temperature sensors) --- htdocs/frontend/javascripts/frontend.js | 40 +++++++++++++++++-------- htdocs/frontend/javascripts/options.js | 2 +- 2 files changed, 29 insertions(+), 13 deletions(-) diff --git a/htdocs/frontend/javascripts/frontend.js b/htdocs/frontend/javascripts/frontend.js index 07ddd45..ffdc021 100644 --- a/htdocs/frontend/javascripts/frontend.js +++ b/htdocs/frontend/javascripts/frontend.js @@ -138,8 +138,8 @@ vz.wui.initEvents = function() { .bind("plotselected", function (event, ranges) { vz.options.plot.xaxis.min = ranges.xaxis.from; vz.options.plot.xaxis.max = ranges.xaxis.to; - vz.options.plot.yaxis.min = null; // autoscaling for neg. values as well - vz.options.plot.yaxis.max = null; // autoscaling + vz.options.plot.yaxis.max = null; // autoscaling + vz.options.plot.yaxis.min = 0; // fixed by 0 vz.entities.loadData(); }) /*.bind('plotpan', function (event, plot) { @@ -148,8 +148,8 @@ vz.wui.initEvents = function() { vz.options.plot.xaxis.max = axes.xaxis.max; vz.options.plot.yaxis.min = axes.yaxis.min; vz.options.plot.yaxis.max = axes.yaxis.max; - })*/ - /*.bind('mouseup', function(event) { + }) + .bind('mouseup', function(event) { vz.entities.loadData(); })*/ .bind('plotzoom', function (event, plot) { @@ -376,24 +376,27 @@ vz.entities.loadData = function() { // update entity table // TODO add units if (entity.data.min) { + if (entity.data.min < vz.options.plot.yaxis.min) { // allow negative values for temperature sensors + vz.options.plot.yaxis.min = entity.data.min; + } + $('#entity-' + entity.uuid + ' .min') - .text(entity.data.min.value) - .attr('title', $.plot.formatDate(new Date(entity.data.min.timestamp), '%d. %b %h:%M:%S', vz.options.plot.xaxis.monthNames)); + .text(vz.wui.formatNumber(entity.data.min[1])) + .attr('title', $.plot.formatDate(new Date(entity.data.min[0]), '%d. %b %h:%M:%S', vz.options.plot.xaxis.monthNames)); } if (entity.data.max) { $('#entity-' + entity.uuid + ' .max') - .text(entity.data.max.value) - .attr('title', $.plot.formatDate(new Date(entity.data.max.timestamp), '%d. %b %h:%M:%S', vz.options.plot.xaxis.monthNames)); + .text(vz.wui.formatNumber(entity.data.max[1])) + .attr('title', $.plot.formatDate(new Date(entity.data.max[0]), '%d. %b %h:%M:%S', vz.options.plot.xaxis.monthNames)); } - // rounding: Math.round rounds to whole numbers; to round to one decimal (e.g. 15.2) we multiply by 10, round and reverse the multiplication again; therefore "vz.options.rounding" needs to be set to 1 (for 1 decimal) in that case if (entity.data.average) { - $('#entity-' + entity.uuid + ' .average').text(Math.round(entity.data.average*Math.pow(10, vz.options.rounding))/Math.pow(10, vz.options.rounding)); + $('#entity-' + entity.uuid + ' .average').text(vz.wui.formatNumber(entity.data.average)); } if (entity.data.consumption) { - $('#entity-' + entity.uuid + ' .consumption').text(Math.round(entity.data.consumption*Math.pow(10, vz.options.rounding))/Math.pow(10, vz.options.rounding)); + $('#entity-' + entity.uuid + ' .consumption').text(vz.wui.formatNumber(entity.data.consumption)); } if (entity.data.tuples) { - $('#entity-' + entity.uuid + ' .last').text(Math.round(entity.data.tuples.last()[1]*Math.pow(10, vz.options.rounding))/Math.pow(10, vz.options.rounding)); + $('#entity-' + entity.uuid + ' .last').text(vz.wui.formatNumber(entity.data.tuples.last()[1])); } }, vz.drawPlot, 'data') ); @@ -401,6 +404,19 @@ vz.entities.loadData = function() { }); }; +/** + * Rounding precission + * + * Math.round rounds to whole numbers + * to round to one decimal (e.g. 15.2) we multiply by 10, + * round and reverse the multiplication again + * therefore "vz.options.precission" needs + * to be set to 1 (for 1 decimal) in that case + */ +vz.wui.formatNumber = function(number) { + return Math.round(number*Math.pow(10, vz.options.precission))/Math.pow(10, vz.options.precission); +} + vz.wui.updateHeadline = function() { var from = $.plot.formatDate(new Date(vz.options.plot.xaxis.min + vz.options.timezoneOffset), '%d. %b %h:%M:%S', vz.options.plot.xaxis.monthNames); var to = $.plot.formatDate(new Date(vz.options.plot.xaxis.max + vz.options.timezoneOffset), '%d. %b %h:%M:%S', vz.options.plot.xaxis.monthNames); diff --git a/htdocs/frontend/javascripts/options.js b/htdocs/frontend/javascripts/options.js index f61cf10..7c4b299 100644 --- a/htdocs/frontend/javascripts/options.js +++ b/htdocs/frontend/javascripts/options.js @@ -29,7 +29,7 @@ vz.options = { language: 'de', backendUrl: '../backend.php', tuples: 300, - rounding: 1, + precission: 2, render: 'lines', refresh: false, defaultInterval: 24*60*60*1000, // 1 day