Skip to content

Commit b3a765d

Browse files
authored
adding pivot files
1 parent dc4ab0e commit b3a765d

File tree

2 files changed

+41
-0
lines changed

2 files changed

+41
-0
lines changed

fastpivot.js

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
function fastpivot(arr){
2+
"use strict";
3+
var obj={};
4+
if(typeof arr!="string" && arr.length>0){
5+
6+
//get columns
7+
var thekeys = Object.keys(arr[0]);
8+
9+
var temp={};
10+
11+
//loop through columns
12+
thekeys.forEach(function(f){
13+
temp[f]={};
14+
temp[f]["_labels"]=[];
15+
temp[f]["_labelsdata"]=[];
16+
temp[f]["_data"]={};
17+
});
18+
19+
//loop all rows and for each column, store values
20+
arr.forEach(function(f,i){
21+
thekeys.forEach(function(a){
22+
var value=f[a];
23+
temp[a]["_data"][value]=(temp[a]["_data"][value] || 0)+1;
24+
temp[a]["_labels"][value]=null;
25+
});
26+
});
27+
28+
//now reloop the columns to store unique values
29+
thekeys.forEach(function(f){
30+
for(var i in temp[f]["_data"]){
31+
temp[f]["_labelsdata"].push(temp[f]["_data"][i]);
32+
}
33+
temp[f]["_labels"]=Object.keys(temp[f]["_labels"]);
34+
});
35+
36+
obj._total=temp.length;
37+
obj=temp;
38+
}
39+
return obj;
40+
}

fastpivot.min.js

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)