|
5 | 5 | <link rel="stylesheet" type="text/css" href="../dist/pivot.css">
|
6 | 6 | <script type="text/javascript" src="ext/jquery-1.8.3.min.js"></script>
|
7 | 7 | <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> |
8 | 9 | <script type="text/javascript" src="../dist/pivot.js"></script>
|
9 | 10 | <style>
|
10 | 11 | * {font-family: Verdana;}
|
|
15 | 16 | $(function(){
|
16 | 17 | var derivers = $.pivotUtilities.derivers;
|
17 | 18 |
|
18 |
| - $.getJSON("mps.json", function(mps) { |
| 19 | + var makePivot = function(mps) { |
19 | 20 | $("#output").pivotUI(mps, {
|
20 | 21 | 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 | +// } |
25 | 27 | },
|
| 28 | +// "derivedAttributesMacros": { |
| 29 | +// "Create Date Month": { |
| 30 | +// "fmt": "%m", |
| 31 | +// "src": "Create Date" |
| 32 | +// } |
| 33 | +// }, |
26 | 34 | onRefresh: function(config) {
|
27 | 35 | var config_copy = JSON.parse(JSON.stringify(config));
|
28 | 36 | //delete some values which are functions
|
|
35 | 43 | $("#config_json").text(JSON.stringify(config_copy, undefined, 2));
|
36 | 44 | }
|
37 | 45 | });
|
| 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]); |
38 | 63 | });
|
39 |
| - }); |
| 64 | + }) |
40 | 65 | </script>
|
41 | 66 | <p><a href="index.html">« back to examples</a></p>
|
42 | 67 | <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> |
43 | 69 | <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;"> |
45 | 71 | </textarea>
|
46 | 72 | <div id="output" style="margin: 30px;"></div>
|
47 | 73 |
|
|
0 commit comments