Skip to content

Commit

Permalink
fix for considering all rows in a column for percentage calculation
Browse files Browse the repository at this point in the history
  • Loading branch information
arajajyothibabu committed Sep 16, 2017
1 parent 3cca838 commit 5951eeb
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 8 deletions.
6 changes: 4 additions & 2 deletions lib/reactcohortgraph.js
Original file line number Diff line number Diff line change
Expand Up @@ -3095,7 +3095,7 @@ var _initialiseProps = function _initialiseProps() {

if (index < 2) return;
var value = _this._sumOfColumnWithIndex(_this.store[key], index);
var percent = _this._getPercentage(_this._sumOfFirstColumnUpToIndex(_this.store[key], totalRows - index), value);
var percent = _this._getPercentage(_this._sumOfFirstColumnUpToIndex(_this.store[key], totalRows), value);
_this.headers[key].push((_this$headers$key$pus = {
isHeader: true,
index: index,
Expand Down Expand Up @@ -3133,9 +3133,11 @@ var _initialiseProps = function _initialiseProps() {
var sum = 0;
for (var i = 0; i <= index; i++) {
try {
//FIXME: need better understanding than this
sum += arr[i][1].value;
} catch (e) {
sum += 0;
//if no further index break the loop
break;
}
}
return sum;
Expand Down
2 changes: 1 addition & 1 deletion lib/reactcohortgraph.min.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "react-cohort-graph",
"version": "0.6.0",
"version": "0.8.0",
"description": "Cohort Analysis Graph with ReactJS",
"main": "lib/reactcohortgraph.js",
"scripts": {
Expand Down
8 changes: 4 additions & 4 deletions src/DataStore.js
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ export default class DataStore {
largeRow.forEach((el, index) => {
if(index < 2) return;
const value = this._sumOfColumnWithIndex(this.store[key], index);
const percent = this._getPercentage(this._sumOfFirstColumnUpToIndex(this.store[key], totalRows - index), value);
const percent = this._getPercentage(this._sumOfFirstColumnUpToIndex(this.store[key], totalRows), value);
this.headers[key].push({
isHeader: true,
index: index,
Expand Down Expand Up @@ -180,10 +180,10 @@ export default class DataStore {
_sumOfFirstColumnUpToIndex = (arr, index) => {
let sum = 0;
for(let i = 0; i <= index; i++){
try {
try { //FIXME: need better understanding than this
sum += arr[i][1].value;
}catch(e){
sum += 0;
}catch(e){ //if no further index break the loop
break;
}
}
return sum;
Expand Down

0 comments on commit 5951eeb

Please sign in to comment.