forked from rwjblue/pivot.js
-
Notifications
You must be signed in to change notification settings - Fork 2
/
index.html
210 lines (191 loc) · 9.4 KB
/
index.html
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
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en-us">
<head>
<title>Pivot.js</title>
<!-- Twitter Bootstrap -->
<link rel="stylesheet" href="./lib/css/bootstrap.min.css" type="text/css" />
<link rel="stylesheet" href="./lib/css/subnav.css" type="text/css" />
<link rel="stylesheet" href="./lib/css/pivot.css" type="text/css" />
<script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js"></script>
<script type="text/javascript" src="./lib/javascripts/subnav.js"></script>
<script type="text/javascript" src="./lib/javascripts/accounting.min.js"></script>
<script type="text/javascript" src="./lib/javascripts/jquery.dataTables.min.js"></script>
<script type="text/javascript" src="./lib/javascripts/dataTables.bootstrap.js"></script>
<script type="text/javascript">
(function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){
(i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),
m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m)
})(window,document,'script','//www.google-analytics.com/analytics.js','ga');
ga('create', 'UA-42535149-1', 'rjackson.github.io');
ga('send', 'pageview');
</script>
<!-- jquery_pivot must be loaded after pivot.js and jQuery -->
<script type="text/javascript" src="./pivot.js"></script>
<script type="text/javascript" src="./jquery_pivot.js"></script>
</head>
<body>
<div class="navbar navbar-fixed-top">
<div class="navbar-inner">
<div class="container">
<ul class="nav">
<li class="active">
<a class="brand" href="https://github.com/rjackson/pivot.js">Pivot.js</a>
</li>
<li><a href="https://github.com/rjackson/pivot.js">Fork On Github</a></li>
<li><a href="./spec/runner.html">Run Spec</a></li>
<li><a href="./docs/index.html#!/api/Pivot">Docs</a></li>
</ul>
</div>
</div>
</div>
<div class="container">
<h1>Pivot.js</h1>
<p>Pivot.js is a simple way to summarize large data sets on the fly. On this page we are using the pivot jQuery plugin which offers a nice entry point to Pivot.js.
<br/><br/>
The data for the chart below is based on a CSV file of about 5000 rows. It is generated by a <a href="https://github.com/rjackson/pivot.js/blob/master/demo_csv_builder.rb">script</a> included in the repository. It is designed to have many fields that have at least some significant relationships between one another. This only just scratches the surface of what Pivot.js can do. Check out the <a href="https://github.com/rjackson/pivot.js/blob/master/README.md">README</a> for more information. Also feel free to run the spec (found in the link up top), and if you spot any problems let us know so we can fix them.
<br/><br/>
<b>To begin:</b>
<ul>
<li>Select the fields you would like to display from the Label Fields/Summary Fields drop down.</li>
<li>Then filter your data by selecting from the filters drop down.</li>
<li>Ta-da, you have yourself a custom report!</li>
</ul>
</p>
<div class="subnav">
<ul class="nav nav-pills">
<li class="dropdown">
<a class="dropdown-toggle" data-toggle="dropdown" href="#">
Filter Fields
<b class="caret"></b>
</a>
<ul class="dropdown-menu stop-propagation" style="overflow:auto;max-height:450px;padding:10px;">
<div id="filter-list"></div>
</ul>
</li>
<li class="dropdown">
<a class="dropdown-toggle" data-toggle="dropdown" href="#">
Row Label Fields
<b class="caret"></b>
</a>
<ul class="dropdown-menu stop-propagation" style="overflow:auto;max-height:450px;padding:10px;">
<div id="row-label-fields"></div>
</ul>
</li>
<li class="dropdown">
<a class="dropdown-toggle" data-toggle="dropdown" href="#">
Column Label Fields
<b class="caret"></b>
</a>
<ul class="dropdown-menu stop-propagation" style="overflow:auto;max-height:450px;padding:10px;">
<div id="column-label-fields"></div>
</ul>
</li>
<li class="dropdown">
<a class="dropdown-toggle" data-toggle="dropdown" href="#">
Summary Fields
<b class="caret"></b>
</a>
<ul class="dropdown-menu stop-propagation" style="overflow:auto;max-height:450px;padding:10px;">
<div id="summary-fields"></div>
</ul>
</li>
<li class="dropdown pull-right">
<a class="dropdown-toggle" data-toggle="dropdown" href="#">
Canned Reports
<b class="caret"></b>
</a>
<ul class="dropdown-menu">
<li><a id="ar-aged-balance" href="#">AR Aged Balance</a></li>
<li><a id="acme-detail-report" href="#">Acme Corp Detail</a></li>
<li><a id="miami-invoice-detail" href="#">Miami Invoice Detail</a></li>
</ul>
</li>
</ul>
</div>
<hr/>
<h1>Results</h1>
<span id="pivot-detail"></span>
<hr/>
<div id="results"></div>
</div>
</body>
<script type="text/javascript">
function ageBucket(row, field){
var age = Math.abs(((new Date().getTime()) - row[field.dataSource])/1000/60/60/24);
switch (true){
case (age < 31):
return '000 - 030'
case (age < 61):
return '031 - 060'
case (age < 91):
return '061 - 090'
case (age < 121):
return '091 - 120'
default:
return '121+'
}
};
// Define the structure of fields, if this is not defined then all fields will be assumed
// to be strings. Name must match csv header row (which must exist) in order to parse correctly.
var fields = [
// filterable fields
{name: 'last_name', type: 'string', filterable: true, filterType: 'regexp'},
{name: 'first_name', type: 'string', filterable: true},
{name: 'state', type: 'string', filterable: true},
{name: 'employer', type: 'string', filterable: true},
{name: 'city', type: 'string', filterable: true},
{name: 'invoice_date', type: 'date', filterable: true},
// psuedo fields
{name: 'invoice_mm', type: 'string', filterable: true, pseudo: true,
pseudoFunction: function(row){
var date = new Date(row.invoice_date);
return pivot.utils().padLeft((date.getMonth() + 1),2,'0')}
},
{name: 'invoice_yyyy_mm', type: 'string', filterable: true, pseudo: true,
pseudoFunction: function(row){
var date = new Date(row.invoice_date);
return date.getFullYear() + '_' + pivot.utils().padLeft((date.getMonth() + 1),2,'0')}
},
{name: 'invoice_yyyy', type: 'string', filterable: true, pseudo: true, columnLabelable: true,
pseudoFunction: function(row){ return new Date(row.invoice_date).getFullYear() }},
{name: 'age_bucket', type: 'string', filterable: true, columnLabelable: true, pseudo: true, dataSource: 'last_payment_date', pseudoFunction: ageBucket},
// summary fields
{name: 'billed_amount', type: 'float', rowLabelable: false, summarizable: 'sum', displayFunction: function(value){ return accounting.formatMoney(value)}},
{name: 'payment_amount', type: 'float', rowLabelable: false, summarizable: 'sum', displayFunction: function(value){ return accounting.formatMoney(value)}},
{name: 'balance', type: 'float', rowLabelable: false, pseudo: true,
pseudoFunction: function(row){ return row.billed_amount - row.payment_amount },
summarizable: 'sum', displayFunction: function(value){ return accounting.formatMoney(value)}},
{name: 'last_payment_date', type: 'date', filterable: true}
]
function setupPivot(input){
input.callbacks = {afterUpdateResults: function(){
$('#results > table').dataTable({
"sDom": "<'row'<'span6'l><'span6'f>>t<'row'<'span6'i><'span6'p>>",
"iDisplayLength": 50,
"aLengthMenu": [[25, 50, 100, -1], [25, 50, 100, "All"]],
"sPaginationType": "bootstrap",
"oLanguage": {
"sLengthMenu": "_MENU_ records per page"
}
});
}};
$('#pivot-demo').pivot_display('setup', input);
};
$(document).ready(function() {
setupPivot({url:'./lib/csv/demo.csv', fields: fields, filters: {employer: 'Acme Corp'}, rowLabels:["city"], summaries:["billed_amount", "payment_amount"]})
// prevent dropdown from closing after selection
$('.stop-propagation').click(function(event){
event.stopPropagation();
});
// **Sexy** In your console type pivot.config() to view your current internal structure (the full initialize object). Pass it to setup and you have a canned report.
$('#ar-aged-balance').click(function(event){
$('#pivot-demo').pivot_display('reprocess_display', {rowLabels:["employer"], columnLabels:["age_bucket"], summaries:["balance"]})
});
$('#acme-detail-report').click(function(event){
$('#pivot-demo').pivot_display('reprocess_display', {filters:{"employer":"Acme Corp"},rowLabels:["city","last_name","first_name","state","invoice_date"]})
});
$('#miami-invoice-detail').click(function(event){
$('#pivot-demo').pivot_display('reprocess_display', {"filters":{"city":"Miami"},"rowLabels":["last_name","first_name","employer","invoice_date"],"summaries":["payment_amount"]})
});
});
</script>