-
Notifications
You must be signed in to change notification settings - Fork 16
/
index.html
311 lines (285 loc) · 8.09 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
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
<!DOCTYPE html>
<html>
<head>
<title>Map Dashboard</title>
<meta charset="UTF-8">
<meta content='width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0' name='viewport'>
<link type="text/css" href="css/leaflet.css" rel="stylesheet"/>
<link type="text/css" href="css/leaflet.markercluster.css" rel="stylesheet"/>
<link type="text/css" href="css/dc.css" rel="stylesheet"/>
<link type="text/css" href="css/bootstrap.min.css" rel="stylesheet">
<link type="text/css" href="css/jquery.dataTables.min.css" rel="stylesheet">
<style>
h4 span {
font-size:14px;
font-weight:normal;
}
h2 {
float: left;
}
h2 span {
font-size:14px;
font-weight:normal;
}
.dc-chart g.row text {
fill: black;
font-size: 10px;
}
label {
font: bold 12px sans-serif;
}
</style>
</head>
<body>
<div class='container' id='main-container'>
<div class='content'>
<div class='container' style='font: 12px sans-serif;'>
<div class = 'row'>
<div class="col-xs-10 dc-data-count" style = 'float:left;'>
<h2>Nashville Building Permits Dashboard
<span>
<span class="filter-count"></span>
selected out of
<span class="total-count"></span>
records
</span>
</h2>
</div>
</div>
<div class = 'row'>
<div class='col-xs-9' id='dc-map-chart'>
<h3>
Map - Building permits
<span>
<a class="reset"
href="#" id="mapReset"
style="display: none;">
reset
</a>
</span>
</h3>
</div>
<div class='col-xs-3' id = 'dc-row-chart'>
<h3>
Row Chart - Cities
<span>
<a class="reset"
href="javascript:rowChart.filterAll();dc.redrawAll();"
style="display: none;">
reset
</a>
</span>
</h3>
</div>
</div>
<div class='row'>
<div class='col-xs-12' id='dc-time-chart'>
<h3>Bar Chart - Permits by issuance date</h3>
</div>
</div>
<div class='row'>
<div class='col-xs-12'>
<h3>Data Table</h3>
<table class='table table-hover' id='dc-table-chart'>
<thead>
<tr class='header'>
<th>Issuance Date</th>
<th>Contact</th>
<th>City</th>
<th>Permit Type</th>
<th>Address</th>
</tr>
</thead>
</table>
</div>
</div>
</div>
</div>
</div>
<script type="text/javascript" src="js/d3.js"></script>
<script type="text/javascript" src="js/crossfilter.js"></script>
<script type="text/javascript" src="js/dc.js"></script>
<script type="text/javascript" src="js/leaflet.js"></script>
<script type="text/javascript" src='js/jquery.js'></script>
<script type="text/javascript" src='js/jquery.dataTables.min.js'></script>
<script type="text/javascript" src='js/bootstrap.min.js'></script>
<script type="text/javascript" src="js/leaflet.markercluster.js"></script>
<script type="text/javascript" src="js/dc.leaflet.js"></script>
<script type="text/javascript">
//connect charts to their appropriate selectors
var mapChart = dc_leaflet.markerChart("#dc-map-chart");
var rowChart = dc.rowChart("#dc-row-chart");
var timeChart = dc.barChart("#dc-time-chart");
var dataCount = dc.dataCount(".dc-data-count");
var datatable = $('#dc-table-chart');
//initial map view
var defaultCenter = [42.69,25.42];
var defaultZoom = 1;
d3.json("data/nashPermits.json", function(data) {
var dateFormat = d3.time.format("%Y-%m-%dT%H:%M:%S");
data.forEach( function(d,i) {
d.date_e = dateFormat.parse(d.date_entered);
d.date_i = dateFormat.parse(d.date_issued);
//handle missing values for table variables
d.contact = d.contact ? d.contact : "MISSING";
d.city = d.city ? d.city : "MISSING";
d.permit_type_description = d.permit_type_description ? d.permit_type_description : "MISSING";
d.address = d.address ? d.address : "MISSING";
d.purpose = d.purpose ? d.purpose: "MISSING";
// parse lat lng-data
if (d.mapped_location.latitude!=null && d.mapped_location.latitude!=undefined) {
d.geo = d.mapped_location.latitude + "," + d.mapped_location.longitude;
} else {
d.geo = "40.7141667,-74.0063889" //dummy coordinates, NYC
}
});
//toplevel crossfilter
var xf = crossfilter(data);
//counter
var all = xf.groupAll();
dataCount.dimension(xf)
.group(all);
//map
var facilities = xf.dimension(function(d) { return d.geo; });
mapChart.dimension(facilities)
.group(facilities.group())
.width(630)
.height(300)
.margins({top: 10, right: 10, bottom: 20, left: 40})
.center(defaultCenter)
.zoom(defaultZoom)
.renderPopup(false)
.brushOn(true)
.cluster(true)
.filterByArea(true);
//row chart
var cities = xf.dimension(function(d) { return d.city; });
rowChart.height(300)
.width(330)
.margins({top: 10, right: 10, bottom: 20, left: 40})
.dimension(cities)
.group(cities.group())
.ordering(function (p) {
return -p.value;
})
.elasticX(true);
//time series bar chart
var issuanceDates = xf.dimension(function (d) { return d.date_i; });
timeChart.width(960)
.height(200)
.margins({top: 10, right: 10, bottom: 20, left: 40})
.dimension(issuanceDates)
.group(issuanceDates.group(d3.time.day))
.transitionDuration(500)
.elasticY(true)
.x(d3.time.scale().domain([new Date(2014, 6, 1), new Date(2014, 12, 31)]))
.round(d3.time.day.round)
.xUnits(d3.time.days)
.elasticY(true)
.elasticX(true)
.xAxis().ticks(5);
//table
//dimension for table search
var tableDimension = xf.dimension(function (d) { return d.contact.toLowerCase() + ' ' +
d.city.toLowerCase() + ' ' +
d.permit_type_description.toLowerCase() + ' ' +
d.address.toLowerCase() + ' ' +
d.purpose.toLowerCase();});
//set options and columns
var dataTableOptions = {
"bSort": true,
columnDefs: [
{
targets: 0,
data: function (d) { return d.date_i; },
type: 'date',
defaultContent: 'Not found'
},
{
targets: 1,
data: function (d) { return d.contact; },
defaultContent: ''
},
{
targets: 2,
data: function (d) { return d.city; },
defaultContent: ''
},
{
targets: 3,
data: function (d) { return d.permit_type_description;},
defaultContent: ''
},
{
targets: 4,
data: function (d) {return d.address;},
defaultContent: ''
},
{
targets: 5, //search column
data: function (d) {return d.purpose;},
defaultContent: '',
visible: false
}
]
};
//initialize datatable
datatable.dataTable(dataTableOptions);
//row details
function format ( d ) {
return '<b>Purpose: </b>' + d.purpose;
}
datatable.DataTable().on('click', 'tr[role="row"]', function () {
var tr = $(this);
var row = datatable.DataTable().row( tr );
if ( row.child.isShown() ) {
// This row is already open - close it
row.child.hide();
tr.removeClass('shown');
}
else {
// Open this row
row.child( format(row.data()) ).show();
tr.addClass('shown');
}
} );
//custom refresh function, see http://stackoverflow.com/questions/21113513/dcjs-reorder-datatable-by-column/21116676#21116676
function RefreshTable() {
dc.events.trigger(function () {
alldata = tableDimension.top(Infinity);
datatable.fnClearTable();
datatable.fnAddData(alldata);
datatable.fnDraw();
});
}
//call RefreshTable when dc-charts are filtered
for (var i = 0; i < dc.chartRegistry.list().length; i++) {
var chartI = dc.chartRegistry.list()[i];
chartI.on("filtered", RefreshTable);
}
//filter all charts when using the datatables search box
$(":input").on('keyup',function(){
text_filter(tableDimension, this.value);//cities is the dimension for the data table
function text_filter(dim,q){
if (q!='') {
dim.filter(function(d){
return d.indexOf (q.toLowerCase()) !== -1;
});
} else {
dim.filterAll();
}
RefreshTable();
dc.redrawAll();}
});
//reset map view on clicking the reset button
$("#mapReset").on('click', function() {
mapChart.map().setView(defaultCenter, defaultZoom);
});
//initial table refresh
RefreshTable();
//initialize other charts
dc.renderAll();
});
</script>
</body>
</html>