From 5e32ffaec490388bbc001e5ae4f16c55d3163e05 Mon Sep 17 00:00:00 2001 From: charithag Date: Wed, 5 Aug 2015 13:34:26 +0530 Subject: [PATCH] Fix bug in bar graph --- .../units/analytics/public/js/graph_util.js | 24 +++++++++++++++---- 1 file changed, 20 insertions(+), 4 deletions(-) diff --git a/modules/distribution/src/repository/jaggeryapps/iotserver/units/analytics/public/js/graph_util.js b/modules/distribution/src/repository/jaggeryapps/iotserver/units/analytics/public/js/graph_util.js index 81ddc517..e6bf8cea 100644 --- a/modules/distribution/src/repository/jaggeryapps/iotserver/units/analytics/public/js/graph_util.js +++ b/modules/distribution/src/repository/jaggeryapps/iotserver/units/analytics/public/js/graph_util.js @@ -322,7 +322,7 @@ function drawLineGraph(graphId, chartDataRaw) { } graphConfig['series'].push({ 'color': color[k], - 'data': summerize(chartData), + 'data': summerizeLine(chartData), 'name': chartDataRaw[i].device }); } @@ -415,7 +415,7 @@ function drawBarGraph(graphId, chartDataRaw) { } graphConfig['series'].push({ 'color': color[k], - 'data': summerize(chartData), + 'data': summerizeBar(chartData), 'name': chartDataRaw[i].device }); } @@ -516,7 +516,7 @@ function convertDate(date) { + hour + ":" + (('' + minute).length < 2 ? '0' : '') + minute; } -function summerize(data) { +function summerizeLine(data) { if (data.length > 1500) { var nData = []; var i = 1; @@ -526,7 +526,23 @@ function summerize(data) { nData.push({x: t_avg, y: v_avg}); i += 2; } - return summerize(nData); + return summerizeLine(nData); + } else { + return data; + } +} + +function summerizeBar(data) { + if (data.length > 1500) { + var nData = []; + var i = 1; + while (i < data.length - 1) { + var t_avg = (data[i - 1].x + data[i].x) / 2; + var v_avg = (data[i - 1].y + data[i].y + data[i+1].y) / 3; + nData.push({x: t_avg, y: Math.round(v_avg)}); + i += 2; + } + return summerizeBar(nData); } else { return data; }