Skip to content

Commit bba608e

Browse files
committed
Temp commit of OnRefresh opt storage
1 parent 18a6359 commit bba608e

File tree

1 file changed

+33
-7
lines changed

1 file changed

+33
-7
lines changed

examples/onrefresh.html

Lines changed: 33 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
<link rel="stylesheet" type="text/css" href="../dist/pivot.css">
66
<script type="text/javascript" src="ext/jquery-1.8.3.min.js"></script>
77
<script type="text/javascript" src="ext/jquery-ui-1.9.2.custom.min.js"></script>
8+
<script type="text/javascript" src="ext/jquery.csv-0.71.min.js"></script>
89
<script type="text/javascript" src="../dist/pivot.js"></script>
910
<style>
1011
* {font-family: Verdana;}
@@ -15,14 +16,21 @@
1516
$(function(){
1617
var derivers = $.pivotUtilities.derivers;
1718

18-
$.getJSON("mps.json", function(mps) {
19+
var makePivot = function(mps) {
1920
$("#output").pivotUI(mps, {
2021
derivedAttributes: {
21-
"Age Bin": derivers.bin("Age", 10),
22-
"Gender Imbalance": function(mp) {
23-
return mp["Gender"] == "Male" ? 1 : -1;
24-
}
22+
// "Doug": derivers.dateFormat("Create Date", "%y"),
23+
// "Age Bin": derivers.bin("Age", 10),
24+
// "Gender Imbalance": function(mp) {
25+
// return mp["Gender"] == "Male" ? 1 : -1;
26+
// }
2527
},
28+
// "derivedAttributesMacros": {
29+
// "Create Date Month": {
30+
// "fmt": "%m",
31+
// "src": "Create Date"
32+
// }
33+
// },
2634
onRefresh: function(config) {
2735
var config_copy = JSON.parse(JSON.stringify(config));
2836
//delete some values which are functions
@@ -35,13 +43,31 @@
3543
$("#config_json").text(JSON.stringify(config_copy, undefined, 2));
3644
}
3745
});
46+
};
47+
48+
$.getJSON("mps.json", makePivot);
49+
$("#csv").bind("change", function(event){
50+
var reader = new FileReader();
51+
reader.onload = function(theFile) {
52+
try {
53+
var input = $.csv.toArrays(theFile.target.result);
54+
55+
}
56+
catch(e) {
57+
alert("CSV Parse error: " + e.message );
58+
return;
59+
}
60+
makePivot(input);
61+
}
62+
reader.readAsText(event.target.files[0]);
3863
});
39-
});
64+
})
4065
</script>
4166
<p><a href="index.html">&laquo; back to examples</a></p>
4267
<p style="width: 800px">Textarea below will refresh will display the configuration object every time a user interacts, using the "onRefresh" parameter. Instead of showing the configuration in a textarea, one could store the configuration in a cookie or implement a "save configuration" feature.</p>
68+
<p>Select a CSV file: <input id="csv" type="file" /></p>
4369
<textarea id="config_json"
44-
style="float: left; width: 250px; height: 500px; margin: 10px;" readonly>
70+
style="float: left; width: 250px; height: 250px; margin: 10px;">
4571
</textarea>
4672
<div id="output" style="margin: 30px;"></div>
4773

0 commit comments

Comments
 (0)