Skip to content

Commit

Permalink
getting started with class based library
Browse files Browse the repository at this point in the history
  • Loading branch information
pat310 committed Jan 30, 2017
1 parent a9ec1c4 commit b2fe9aa
Show file tree
Hide file tree
Showing 7 changed files with 636 additions and 527 deletions.
56 changes: 45 additions & 11 deletions lib/quick-pivot.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion lib/quick-pivot.js.map

Large diffs are not rendered by default.

24 changes: 22 additions & 2 deletions src/index.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,23 @@
'use strict';
import { tableCreator } from './logic';

module.exports = require('./logic.js');
export default class Pivot {

constructor(data, rows, cols, agg, type, header) {
this.rows = rows;
this.cols = cols;
this.agg = agg;
this.type = type;
this.header = header;
this.data = tableCreator(data, rows, cols, agg, type, header);
}

getData() {
return this.data;
}

setData(data) {
this.data = tableCreator(
data, this.rows, this.cols, this.agg, this.type, this.header);
}

}
12 changes: 1 addition & 11 deletions src/logic.js
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ function checkPivotCategories(actualCats, selectedCats) {
}
}

function tableCreator(
export function tableCreator(
data, rows = [], cols = [], accCatOrCB, accTypeOrInitVal, rowHeader) {
data = fixDataFormat(data);
if (!data.length) return [];
Expand Down Expand Up @@ -223,13 +223,3 @@ function tableCreator(
};

}

module.exports = {
tableCreator,
fixDataFormat,
groupByCategory,
groupByCategories,
createColumnHeaders,
accumulator,
checkPivotCategories
};
37 changes: 37 additions & 0 deletions test/index.spec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
import chai from 'chai';

import Pivot from '../lib/quick-pivot';

chai.expect();
const expect = chai.expect;

var dataArray = [
['name', 'gender', 'house', 'age'],
['Jon', 'm', 'Stark', 14],
['Arya', 'f', 'Stark', 10],
['Cersei', 'f', 'Baratheon', 38],
['Tywin', 'm', 'Lannister', 67],
['Tyrion', 'm', 'Lannister', 34],
['Joffrey', 'm', 'Baratheon', 18],
['Bran', 'm', 'Stark', 8],
['Jaime', 'm', 'Lannister', 32],
['Sansa', 'f', 'Stark', 12]
];

var rowsToPivot = ['name'];
var colsToPivot = ['house', 'gender'];
var aggregationCategory = 'age';
var aggregationType = 'sum';

var pivot = new Pivot(
dataArray,
rowsToPivot,
colsToPivot,
aggregationCategory,
aggregationType);

describe('this is a test', function() {
it('is this a pivot?', function() {
console.log('testing 1 2 3', pivot.getData());
});
});
Loading

0 comments on commit b2fe9aa

Please sign in to comment.