diff --git a/htdocs/frontend/javascripts/frontend.js b/htdocs/frontend/javascripts/frontend.js index cc566be..6d30781 100644 --- a/htdocs/frontend/javascripts/frontend.js +++ b/htdocs/frontend/javascripts/frontend.js @@ -359,6 +359,7 @@ vz.entities.each = function(cb) { * Load json data from the backend */ vz.entities.loadData = function() { + vz.wui.updateHeadline(); $('#overlay').html('loading...

loading...

'); this.each(function(entity, parent) { if (entity.active && entity.type != 'group') { // TODO add group data aggregation @@ -387,8 +388,8 @@ vz.entities.loadData = function() { $('#entity-' + entity.uuid + ' .average').text(Math.round(entity.data.average*Math.pow(10, vz.options.rounding))/Math.pow(10, vz.options.rounding)); // 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.last) { - $('#entity-' + entity.uuid + ' .last').text(Math.round(entity.data.last*Math.pow(10, vz.options.rounding))/Math.pow(10, vz.options.rounding)); + 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)); } }, vz.drawPlot, 'data') ); @@ -406,11 +407,9 @@ vz.wui.updateHeadline = function() { * Draws plot to container */ vz.drawPlot = function () { - vz.wui.updateHeadline(); - var data = new Array; vz.entities.each(function(entity, parent) { - if (entity.active && entity.data && entity.data.count > 0) { + if (entity.active && entity.data && entity.data.tuples && entity.data.tuples.length > 0) { data.push({ data: entity.data.tuples, color: entity.color diff --git a/htdocs/frontend/javascripts/helper.js b/htdocs/frontend/javascripts/helper.js index 20ff51a..b60a739 100644 --- a/htdocs/frontend/javascripts/helper.js +++ b/htdocs/frontend/javascripts/helper.js @@ -78,7 +78,7 @@ Array.prototype.clear = function() { this.length = 0; } -Array.prototype.unique = function () { +Array.prototype.unique = function() { var r = new Array(); this.each(function(key, value) { if (!r.contains(value)) { @@ -87,3 +87,7 @@ Array.prototype.unique = function () { }); return r; } + +Array.prototype.last = function() { + return (this.length > 0) ? this[this.length-1] : null; +}