|
15 | 15 | <script type="text/javascript">
|
16 | 16 | $(function(){
|
17 | 17 | var derivers = $.pivotUtilities.derivers;
|
| 18 | + var data; |
18 | 19 |
|
| 20 | + var Refresh = function(config) { |
| 21 | + var config_copy = JSON.parse(JSON.stringify(config)); |
| 22 | + //delete some values which are functions |
| 23 | + delete config_copy["aggregators"]; |
| 24 | + delete config_copy["renderers"]; |
| 25 | + delete config_copy["derivedAttributes"]; |
| 26 | + //delete some bulky default values |
| 27 | + delete config_copy["rendererOptions"]; |
| 28 | + delete config_copy["localeStrings"]; |
| 29 | + $("#config_json").text(JSON.stringify(config_copy, undefined, 2)); |
| 30 | + } |
19 | 31 | var makePivot = function(mps) {
|
20 | 32 | $("#output").pivotUI(mps, {
|
21 | 33 | derivedAttributes: {
|
|
31 | 43 | // "src": "Create Date"
|
32 | 44 | // }
|
33 | 45 | // },
|
34 |
| - onRefresh: function(config) { |
35 |
| - var config_copy = JSON.parse(JSON.stringify(config)); |
36 |
| - //delete some values which are functions |
37 |
| - delete config_copy["aggregators"]; |
38 |
| - delete config_copy["renderers"]; |
39 |
| - delete config_copy["derivedAttributes"]; |
40 |
| - //delete some bulky default values |
41 |
| - delete config_copy["rendererOptions"]; |
42 |
| - delete config_copy["localeStrings"]; |
43 |
| - $("#config_json").text(JSON.stringify(config_copy, undefined, 2)); |
44 |
| - } |
| 46 | + onRefresh: Refresh |
45 | 47 | });
|
46 | 48 | };
|
47 |
| - |
48 | 49 | $.getJSON("mps.json", makePivot);
|
49 | 50 | $("#csv").bind("change", function(event){
|
50 | 51 | var reader = new FileReader();
|
51 | 52 | reader.onload = function(theFile) {
|
52 | 53 | try {
|
53 |
| - var input = $.csv.toArrays(theFile.target.result); |
| 54 | + data = $.csv.toArrays(theFile.target.result); |
54 | 55 |
|
55 | 56 | }
|
56 | 57 | catch(e) {
|
57 | 58 | alert("CSV Parse error: " + e.message );
|
58 | 59 | return;
|
59 | 60 | }
|
60 |
| - makePivot(input); |
| 61 | + makePivot(data); |
61 | 62 | }
|
62 | 63 | reader.readAsText(event.target.files[0]);
|
63 | 64 | });
|
| 65 | + |
| 66 | + $("#config_json").bind("blur", function(event){ |
| 67 | + var a = JSON.parse($(this).val()); |
| 68 | + a.onRefresh=Refresh; |
| 69 | + a.renderers = $.extend( |
| 70 | + $.pivotUtilities.renderers, |
| 71 | + $.pivotUtilities.gchart_renderers, |
| 72 | + $.pivotUtilities.d3_renderers, |
| 73 | + $.pivotUtilities.jqwidgets_renderers |
| 74 | + ); |
| 75 | + $("#output").pivotUI(data,a,true); |
| 76 | + }); |
64 | 77 | })
|
65 | 78 | </script>
|
66 | 79 | <p><a href="index.html">« back to examples</a></p>
|
|
0 commit comments