Skip to content

Commit

Permalink
Merge 5187012 into 5c82c66
Browse files Browse the repository at this point in the history
  • Loading branch information
turnerniles committed Jan 23, 2018
2 parents 5c82c66 + 5187012 commit 4955afb
Show file tree
Hide file tree
Showing 8 changed files with 58 additions and 58 deletions.
24 changes: 12 additions & 12 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ pivot.data.table
'Baratheon',
'Baratheon',
'Lannister',
'aggregated' ],
'Totals' ],
depth: 0,
type: 'colHeader',
row: 0 },
Expand Down Expand Up @@ -133,7 +133,7 @@ pivot.data.table
type: 'data',
depth: 0,
row: 10 },
{ value: [ '', 22, 22, 38, 18, 133, '' ], type: 'aggregated' } ]
{ value: [ 'Totals', 22, 22, 38, 18, 133, '' ], type: 'aggregated' } ]
```

## API
Expand Down Expand Up @@ -218,7 +218,7 @@ const pivot = new Pivot(dataArray, ['gender'], ['house'], cbFunc, 0, 'average ag

console.log(pivot.data.table);
/*
[ { value: [ 'average age', 'Stark', 'Baratheon', 'Lannister', 'aggregated' ],
[ { value: [ 'average age', 'Stark', 'Baratheon', 'Lannister', 'Totals' ],
depth: 0,
type: 'colHeader',
row: 0 },
Expand All @@ -227,15 +227,15 @@ console.log(pivot.data.table);
type: 'data',
depth: 0,
row: 2 },
{ value: [ '', 11, 28, 44.333333333333336, '' ],
{ value: [ 'Totals', 11, 28, 44.333333333333336, '' ],
type: 'aggregated' } ]
*/

pivot.update(dataArray, ['gender', 'name'], ['house'], cbFunc, 0, 'average age')

console.log(pivot.data.table);
/*
[ { value: [ 'average age', 'Stark', 'Baratheon', 'Lannister', 'aggregated' ],
[ { value: [ 'average age', 'Stark', 'Baratheon', 'Lannister', 'Totals' ],
depth: 0,
type: 'colHeader',
row: 0 },
Expand Down Expand Up @@ -283,15 +283,15 @@ console.log(pivot.data.table);
type: 'data',
depth: 1,
row: 11 },
{ value: [ '', 11, 28, 44.333333333333336, '' ],
{ value: [ 'Totals', 11, 28, 44.333333333333336, '' ],
type: 'aggregated' } ]
*/

pivot.collapse(1);

console.log(pivot.data.table);
/*
[ { value: [ 'average age', 'Stark', 'Baratheon', 'Lannister', 'aggregated' ],
[ { value: [ 'average age', 'Stark', 'Baratheon', 'Lannister', 'Totals' ],
depth: 0,
type: 'colHeader',
row: 0 },
Expand Down Expand Up @@ -327,7 +327,7 @@ console.log(pivot.data.table);
type: 'data',
depth: 1,
row: 11 },
{ value: [ '', 11, 28, 44.333333333333336, '' ],
{ value: [ 'Totals', 11, 28, 44.333333333333336, '' ],
type: 'aggregated' } ]
*/

Expand All @@ -350,7 +350,7 @@ pivot.collapse(2);

console.log(pivot.data.table);
/*
[ { value: [ 'average age', 'Stark', 'Baratheon', 'Lannister', 'aggregated' ],
[ { value: [ 'average age', 'Stark', 'Baratheon', 'Lannister', 'Totals' ],
depth: 0,
type: 'colHeader',
row: 0 },
Expand All @@ -362,14 +362,14 @@ console.log(pivot.data.table);
depth: 0,
type: 'rowHeader',
row: 5 },
{ value: [ '', 11, 28, 44.333333333333336, '' ],
{ value: [ 'Totals', 11, 28, 44.333333333333336, '' ],
type: 'aggregated' } ]
*/

pivot.expand(1);
console.log(pivot.data.table);
/*
[ { value: [ 'average age', 'Stark', 'Baratheon', 'Lannister', 'aggregated' ],
[ { value: [ 'average age', 'Stark', 'Baratheon', 'Lannister', 'Totals' ],
depth: 0,
type: 'colHeader',
row: 0 },
Expand All @@ -393,7 +393,7 @@ console.log(pivot.data.table);
depth: 0,
type: 'rowHeader',
row: 5 },
{ value: [ '', 11, 28, 44.333333333333336, '' ],
{ value: [ 'Totals', 11, 28, 44.333333333333336, '' ],
type: 'aggregated' } ]
```
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "quick-pivot",
"version": "2.4.0",
"version": "2.4.1",
"description": "a utility for quickly pivoting data",
"main": "lib/quick-pivot.min.js",
"scripts": {
Expand Down
4 changes: 2 additions & 2 deletions src/logic.js
Original file line number Diff line number Diff line change
Expand Up @@ -395,7 +395,7 @@ export function tableCreator(data, rows = [], cols = [], accCatOrCB,
return accumulator(accumulatedRawData, accCatOrCB, accTypeOrInitVal);
}

return '';
return 'Totals';
});
}

Expand Down Expand Up @@ -451,7 +451,7 @@ export function tableCreator(data, rows = [], cols = [], accCatOrCB,
tableRow.value = tableRow.value.concat(columnAggregations[counter]);
counter += 1;
} else {
tableRow.value = tableRow.value.concat(i === 0 ? 'aggregated' : '');
tableRow.value = tableRow.value.concat(i === 0 ? 'Totals' : '');
}

return tableRow;
Expand Down
12 changes: 6 additions & 6 deletions test/index/collapse.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ export default () => {

const expectedTable = [
{
value: ['sum age', 'Stark', 'Baratheon', 'Lannister', 'aggregated'],
value: ['sum age', 'Stark', 'Baratheon', 'Lannister', 'Totals'],
depth: 0,
type: 'colHeader',
row: 0,
Expand Down Expand Up @@ -64,7 +64,7 @@ export default () => {
},
{
type: 'aggregated',
value: ['', 44, 56, 133, ''],
value: ['Totals', 44, 56, 133, ''],
},
];

Expand Down Expand Up @@ -138,7 +138,7 @@ export default () => {
pivot.collapse(1).collapse(2);
const expectedTable = [
{
value: ['sum age', 'Stark', 'Baratheon', 'Lannister', 'aggregated'],
value: ['sum age', 'Stark', 'Baratheon', 'Lannister', 'Totals'],
depth: 0,
type: 'colHeader',
row: 0 },
Expand All @@ -155,7 +155,7 @@ export default () => {
},
{
type: 'aggregated',
value: ['', 44, 56, 133, ''],
value: ['Totals', 44, 56, 133, ''],
},
];

Expand All @@ -175,7 +175,7 @@ export default () => {
pivot.collapse(5).collapse(1);
const expectedTable = [
{
value: ['sum age', 'Stark', 'Baratheon', 'Lannister', 'aggregated'],
value: ['sum age', 'Stark', 'Baratheon', 'Lannister', 'Totals'],
depth: 0,
type: 'colHeader',
row: 0 },
Expand All @@ -192,7 +192,7 @@ export default () => {
},
{
type: 'aggregated',
value: ['', 44, 56, 133, ''],
value: ['Totals', 44, 56, 133, ''],
},
];

Expand Down
8 changes: 4 additions & 4 deletions test/index/expand.js
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ export default () => {
);

const expectedTable = [
{ value: [ 'sum age', 'Stark', 'Baratheon', 'Lannister', 'aggregated' ],
{ value: [ 'sum age', 'Stark', 'Baratheon', 'Lannister', 'Totals' ],
depth: 0,
type: 'colHeader',
row: 0 },
Expand All @@ -91,7 +91,7 @@ export default () => {
row: 5 },
{
type: 'aggregated',
value: ['', 44, 56, 133, ''],
value: ['Totals', 44, 56, 133, ''],
},
];

Expand Down Expand Up @@ -183,7 +183,7 @@ export default () => {
'Baratheon',
'Baratheon',
'Lannister',
'aggregated',
'Totals',
],
depth: 0,
type: 'colHeader',
Expand Down Expand Up @@ -251,7 +251,7 @@ export default () => {
},
{
type: 'aggregated',
value: ['', 22, 22, 38, 18, 133, ''],
value: ['Totals', 22, 22, 38, 18, 133, ''],
},
];

Expand Down
32 changes: 16 additions & 16 deletions test/index/filter.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ export default () => {

const expectedResult = [
{
value: [ 'sum age', 'sum age', 'aggregated' ],
value: [ 'sum age', 'sum age', 'Totals' ],
depth: 0,
type: 'colHeader',
row: 0,
Expand All @@ -65,7 +65,7 @@ export default () => {
{ value: [ 'Sansa', 12, 12 ], type: 'data', depth: 2, row: 14 },
{ value: [ 'm', 8, '' ], depth: 1, type: 'rowHeader', row: 15 },
{ value: [ 'Bran', 8, 8 ], type: 'data', depth: 2, row: 16 },
{ type: 'aggregated', value: ['', 219, ''] },
{ type: 'aggregated', value: ['Totals', 219, ''] },
];

pivot.filter('name', ['Jon'], 'exclude');
Expand All @@ -83,7 +83,7 @@ export default () => {
);

const expectedResult = [
{ value: [ 'sum age', 'sum age', 'aggregated' ],
{ value: [ 'sum age', 'sum age', 'Totals' ],
depth: 0,
type: 'colHeader',
row: 0 },
Expand All @@ -109,7 +109,7 @@ export default () => {
{ value: [ 'Sansa', 12, 12 ], type: 'data', depth: 2, row: 14 },
{ value: [ 'm', 8, '' ], depth: 1, type: 'rowHeader', row: 15 },
{ value: [ 'Bran', 8, 8 ], type: 'data', depth: 2, row: 16 },
{type: 'aggregated', value: ['', 219, ''] },
{type: 'aggregated', value: ['Totals', 219, ''] },
];

pivot.filter('name', ['Jon']);
Expand All @@ -128,7 +128,7 @@ export default () => {

const expectedResult = [
{
value: [ 'sum age', 'sum age', 'aggregated' ],
value: [ 'sum age', 'sum age', 'Totals' ],
depth: 0,
type: 'colHeader',
row: 0,
Expand All @@ -140,7 +140,7 @@ export default () => {
{ value: [ 'm', 22, '' ], depth: 1, type: 'rowHeader', row: 5 },
{ value: [ 'Bran', 8, 8 ], type: 'data', depth: 2, row: 6 },
{ value: [ 'Jon', 14, 14 ], type: 'data', depth: 2, row: 7 },
{ type: 'aggregated', value: ['', 44, ''] },
{ type: 'aggregated', value: ['Totals', 44, ''] },
];

function filterFunc(dataRow) {
Expand All @@ -162,7 +162,7 @@ export default () => {
);

const expectedResult = [
{ value: [ 'sum age', 'sum age', 'aggregated'],
{ value: [ 'sum age', 'sum age', 'Totals'],
depth: 0,
type: 'colHeader',
row: 0 },
Expand All @@ -179,7 +179,7 @@ export default () => {
row: 6 },
{ value: [ 'm', 133, '' ], depth: 1, type: 'rowHeader', row: 7 },
{ value: [ 'Stark', 30, '' ], depth: 0, type: 'rowHeader', row: 11 },
{ type: 'aggregated', value: ['', 219, ''] },
{ type: 'aggregated', value: ['Totals', 219, ''] },
];

pivot.collapse(11).collapse(2).collapse(6);
Expand All @@ -200,13 +200,13 @@ export default () => {

const expectedResult = [
{
value: [ 'sum age', 'sum age', 'aggregated' ],
value: [ 'sum age', 'sum age', 'Totals' ],
depth: 0,
type: 'colHeader',
row: 0,
},
{ value: [ 'Stark', 44, '' ], depth: 0, type: 'rowHeader', row: 1 },
{ type: 'aggregated', value: ['', 44, ''] },
{ type: 'aggregated', value: ['Totals', 44, ''] },
];

function filterFunc(dataRow) {
Expand All @@ -231,15 +231,15 @@ export default () => {

const expectedResult = [
{
value: [ 'sum age', 'sum age', 'aggregated' ],
value: [ 'sum age', 'sum age', 'Totals' ],
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, 38 ], type: 'data', depth: 2, row: 3 },
{ type: 'aggregated', value: ['', 38, ''] },
{ type: 'aggregated', value: ['Totals', 38, ''] },
];

pivot.filter('house', ['Stark'], 'exclude')
Expand All @@ -259,7 +259,7 @@ export default () => {
);

const expectedResult = [
{ value: [ 'sum age', 'sum age', 'aggregated' ],
{ value: [ 'sum age', 'sum age', 'Totals' ],
depth: 0,
type: 'colHeader',
row: 0 },
Expand All @@ -280,7 +280,7 @@ export default () => {
{ value: [ 'm', 22, '' ], depth: 1, type: 'rowHeader', row: 11 },
{ value: [ 'Bran', 8, 8 ], type: 'data', depth: 2, row: 12 },
{ value: [ 'Jon', 14, 14 ], type: 'data', depth: 2, row: 13 },
{ type: 'aggregated', value: ['', 96, ''] },
{ type: 'aggregated', value: ['Totals', 96, ''] },
];

pivot.filter('name', ['Cersei'], 'exclude')
Expand All @@ -302,7 +302,7 @@ export default () => {
);

const expectedResult = [
{ value: [ 'sum age', 'sum age', 'aggregated' ],
{ value: [ 'sum age', 'sum age', 'Totals' ],
depth: 0,
type: 'colHeader',
row: 0 },
Expand All @@ -325,7 +325,7 @@ export default () => {
{ value: [ 'm', 22, '' ], depth: 1, type: 'rowHeader', row: 11 },
{ value: [ 'Bran', 8, 8 ], type: 'data', depth: 2, row: 12 },
{ value: [ 'Jon', 14, 14 ], type: 'data', depth: 2, row: 13 },
{ type: 'aggregated', value: ['', 96, ''] },
{ type: 'aggregated', value: ['Totals', 96, ''] },
];

pivot.filter('name', ['Cersei'], 'exclude')
Expand Down
4 changes: 2 additions & 2 deletions test/index/update.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ const dataArray2 = [
export default () => {
it('should return a new pivoted table if not filtering', () => {
const expected = [
{ value: [ 'sum age', 'Stark', 'Lannister', 'Baratheon', 'aggregated' ],
{ value: [ 'sum age', 'Stark', 'Lannister', 'Baratheon', 'Totals' ],
depth: 0,
type: 'colHeader',
row: 0,
Expand All @@ -37,7 +37,7 @@ export default () => {
{ value: [ 'Jaime', '', 32, '', 32 ], type: 'data', depth: 1, row: 5 },
{ value: [ 'Joffrey', '', '', 18, 18 ], type: 'data', depth: 1, row: 6 },
{ value: [ 'Tyrion', '', 34, '', 34 ], type: 'data', depth: 1, row: 7 },
{ type: 'aggregated', value: ['', 20, 66, 18, ''] },
{ type: 'aggregated', value: ['Totals', 20, 66, 18, ''] },
];

const pivot = new Pivot(
Expand Down
Loading

0 comments on commit 4955afb

Please sign in to comment.