-
Notifications
You must be signed in to change notification settings - Fork 0
/
rcsv.js
102 lines (92 loc) · 3.23 KB
/
rcsv.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
$(function(){
var renderers = $.extend(
$.pivotUtilities.renderers,
$.pivotUtilities.c3_renderers,
$.pivotUtilities.d3_renderers,
$.pivotUtilities.export_renderers
);
var data_to_use = null;
var config_to_use = {
rows: ["Package name"],
cols: ["Date"],
aggregatorName: ["Sum"],
vals: ["Download count"],
hiddenAttributes: [""],
renderers: renderers };
function Update() {
$("#output").empty().text("Loading...");
var val = $("#csv").val();
$("#download").prop('disabled', false);
$("#download").on("click", function(){
document.location.href = val;
});
Papa.parse(val, {
download: true,
header: true,
skipEmptyLines: true,
complete: function(parsed){
data_to_use = parsed.data;
console.log("Finished:", data_to_use);
$("#output").pivotUI(data_to_use, config_to_use , true);
}
});
}
Papa.parse("datasets.csv", {
download: true,
header: true,
skipEmptyLines: true,
complete: function(parsed) {
var csvlist_arr = parsed.data;
var pkg = $("<optgroup>", {label: ""});
for(var i in csvlist_arr)
{
var dataset = csvlist_arr[i];
if(dataset.Package != pkg.attr("label"))
{
pkg = $("<optgroup>", {label: dataset.Package}).appendTo($("#csv"));
}
pkg.append($("<option>", {value: dataset.csv}).text(dataset.Item +": " +dataset.Title));
}
$("#csv").chosen();
$("#csv").bind("change", function(event){
console.log(event);
Update();
});
}
});
Papa.parse("config.csv", {
download: true,
header: true,
skipEmptyLines: true,
complete: function(parsed) {
var csvlist_arr = parsed.data;
var pkg = $("<optgroup>", {label: ""});
for(var i in csvlist_arr)
{
var dataset = csvlist_arr[i];
if(dataset.Package != pkg.attr("label"))
{
pkg = $("<optgroup>", {label: dataset.Package}).appendTo($("#template"));
}
pkg.append($("<option>", {value: dataset.csv}).text(dataset.Title));
}
$("#template").chosen();
$("#template").bind("change", function(event){
console.log(event);
$.getJSON( $("#template").val(), function(data) {
config_to_use = data;
console.log(config_to_use);
Update();
});
});
}
});
$("#save").on("click", function(){
var config = $("#output").data("pivotUIOptions");
console.log($("#output"));
var config_copy = JSON.parse(JSON.stringify(config));
delete config_copy["aggregators"];
delete config_copy["renderers"];
console.log(config_copy);
});
});