Skip to content

Commit

Permalink
uneven length fix
Browse files Browse the repository at this point in the history
  • Loading branch information
arajajyothibabu committed Nov 28, 2016
1 parent 2432d80 commit c864831
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 15 deletions.
21 changes: 11 additions & 10 deletions js/options.js
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
9 changes: 4 additions & 5 deletions js/retention-graph.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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);
};

Expand All @@ -368,7 +366,7 @@
span = $('<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);
}
Expand Down Expand Up @@ -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;
};

Expand Down

0 comments on commit c864831

Please sign in to comment.