diff --git a/js/options.js b/js/options.js index 1566d45..bc1846e 100644 --- a/js/options.js +++ b/js/options.js @@ -8,20 +8,21 @@ var options = { "23-05-2016": [300, 200, 150, 50, 20, 20, 90], "24-05-2016": [200, 110, 150, 50, 10, 20], "25-05-2016": [100, 10, 10, 50, 20], - "26-05-2016": [300, 200, 150], - "27-05-2016": [200, 110], - "28-05-2016": [100] + "26-05-2016": [300, 200, 150, 50], + "27-05-2016": [200, 110, 40], + "28-05-2016": [100, 50], + "29-05-2016": [200] }, weeks : { - "week1": [200, 10, 20, 30, 40, 10, 20, 20], - "week2": [300, 200, 150, 50, 20, 20, 90], - "week3": [200, 110, 150, 50, 10, 20] + "week1": [200, 100, 60, 20, 5], + "week2": [300, 200, 100, 50], + "week3": [200, 100, 40], + "week4": [200, 100] }, months : { - "month1": [200, 10, 20, 30, 40, 10, 20, 20], - "month2": [300, 200, 150, 50, 20, 20, 90], - "month3": [200, 110, 150, 50, 10, 20], - "month4": [100, 10, 10, 50, 20] + "month1": [200, 10, 20, 30], + "month2": [300, 200, 150], + "month3": [200, 110] } }, //startDate : "22-05-2016", diff --git a/js/retention-graph.js b/js/retention-graph.js index 19bcf21..7b0ee96 100644 --- a/js/retention-graph.js +++ b/js/retention-graph.js @@ -211,9 +211,9 @@ this.headerValues = new Array(this.options[this.currentSelected] + 2).join('0').split('').map(parseFloat); this.initialValues = new Array(rowsData.length).join('0').split('').map(parseFloat); //initialising to 0 - rowsData.forEach(function(data){ + rowsData.forEach(function(data, index){ _this.generateRow(data).appendTo(tbody); - _this.initialValues.push(data[1]); //pushes initial values before calculating retention. In fact calculating retention for these values + _this.initialValues[index] = data[1]; //pushes initial values before calculating retention. In fact calculating retention for these values }); var tableHeader = this.generateTableHeader(table); tableHeader.appendTo(table); @@ -337,12 +337,10 @@ Retention.prototype.getTotalPercentage = function (value, index) { var total = 0; var threshold = this.initialValues.length - index; - console.log(this.initialValues); this.initialValues.forEach(function (data, i) { if(i < threshold) total += data; }); - console.log(total); return this.getPercentage(total, value); }; @@ -368,7 +366,7 @@ span = $('', { class: 'retention-badge badge-info', text: function () { - return _this.showValue? _this.headerValues[key-1] : _this.getTotalPercentage(_this.headerValues[key-1], key-2) + "%"; + return _this.showValue? _this.headerValues[key-1] : _this.getTotalPercentage(_this.headerValues[key-1], key-1) + "%"; } }).appendTo(td); } @@ -447,6 +445,7 @@ }; Retention.prototype.getPercentage = function (total, value) { + if(total == 0 || value == 0) return 0; //handling Infinity return Math.round((value/total * 100) * 100) / 100; };