Skip to content

Commit

Permalink
progressive filtering draft
Browse files Browse the repository at this point in the history
  • Loading branch information
turnerniles committed Jun 25, 2017
1 parent ee28233 commit 696534b
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 2 deletions.
5 changes: 4 additions & 1 deletion src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ export default class Pivot {
else {
data = fixDataFormat(data);
this.originalArgs = {data, rows, cols, agg, type, header};
this.filteredArgs = {data, rows, cols, agg, type, header};
this.originalData = tableCreator(data, rows, cols, agg, type, header);
this.uniqueValues = createUniqueValues(data);
}
Expand All @@ -48,8 +49,11 @@ export default class Pivot {
this.originalArgs = {data, rows, cols, agg, type, header};
this.uniqueValues = createUniqueValues(data);
}

this.originalData = tableCreator(data, rows, cols, agg, type, header);
this.data = this.originalData;
this.originalArgs.data = data;

this.collapsedRows = {};

return this;
Expand Down Expand Up @@ -144,7 +148,6 @@ export default class Pivot {
filter(this.originalArgs.data, fieldName, filterValues, filterType);
/** collect the original arguments provided */
const {rows, cols, agg, type, header} = this.originalArgs;

/**
* get the current rows that are collapsed in reverse because we
* will recollapse them from bottom to top to ensure nested collapses
Expand Down
2 changes: 1 addition & 1 deletion test/filtering/filter.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { expect } from 'chai';
import { filter } from '../../src/filtering.js';
import Pivot from '../../src';

const data = [
{ name: 'Jon', gender: 'm', house: 'Stark', age: 14 },
Expand Down Expand Up @@ -144,4 +145,3 @@ export default () => {
expect(results).to.deep.equal(data);
});
};

21 changes: 21 additions & 0 deletions test/index/filter.js
Original file line number Diff line number Diff line change
Expand Up @@ -187,4 +187,25 @@ export default () => {

expect(pivot.data.table).to.deep.equal(expectedResult);
});

it('should progressively filter, when the filter method is called in succession', () => {
const pivot = new Pivot(
dataArray,
rowsToPivotTestOne,
colsToPivotTestOne,
aggregationCategory,
aggregationType,
);

const expectedResult = [
{ value: [ 'sum age', 'sum age' ], depth: 0, type: 'colHeader', row: 0 },
{ value: [ 'Baratheon', 38 ], depth: 0, type: 'rowHeader', row: 1 },
{ value: [ 'f', 38 ], depth: 1, type: 'rowHeader', row: 2 },
{ value: [ 'Cersei', 38 ], type: 'data', depth: 2, row: 3 }
]

pivot.filter('house', ['Stark'], 'exclude').filter('gender', ['m'], 'exclude');

expect(pivot.data.table).to.deep.equal(expectedResult);
});
};

0 comments on commit 696534b

Please sign in to comment.