-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathdashboard.html
More file actions
365 lines (336 loc) · 13.4 KB
/
Copy pathdashboard.html
File metadata and controls
365 lines (336 loc) · 13.4 KB
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
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0" <title>Citizen Request Dashboard</title>
<link rel="stylesheet" href="//netdna.bootstrapcdn.com/bootstrap/3.2.0/css/bootstrap.min.css">
<link rel="stylesheet" type="text/css" href="app/css/keen-dashboards.css" />
<link rel="stylesheet" type="text/css" href="//js.arcgis.com/3.11/esri/css/esri.css">
<link rel="stylesheet" type="text/css" href="//esri.github.io/bootstrap-map-js/dist/css/bootstrapmap.min.css">
</head>
<body class="application">
<div class="navbar navbar-inverse navbar-fixed-top" role="navigation">
<div class="container-fluid">
<div class="navbar-header">
<button type="button" class="navbar-toggle" data-toggle="collapse" data-target=".navbar-collapse">
<span class="sr-only">Toggle navigation</span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
</button>
<!-- <a class="navbar-brand hidden-xs" href="#">
<span class="glyphicon glyphicon-chevron-left"></span>
</a> -->
<a class="navbar-brand" href="#">Citizen Request Dashboard</a>
</div>
<div class="navbar-collapse collapse">
<ul class="nav navbar-nav">
<li><a href="index.html">Collector</a></li>
</ul>
<ul class="nav navbar-nav navbar-right">
<li><a href="http://www.cityofredlands.org/">City of Redlands</a></li>
<li><a href="https://github.com/tomwayson/responsive-citizens">Source</a></li>
<li><a href="http://stackoverflow.com/search?q=esri+bootstrap">Support</a></li>
</ul>
</div>
</div>
</div>
<div class="container-fluid">
<div class="row">
<div class="col-sm-6">
<div class="row">
<div class="col-sm-12">
<div class="chart-wrapper">
<div class="chart-title">
Request Severity
</div>
<div class="chart-stage">
<div class="chart left">
<canvas id="severity-chart"></canvas>
</div>
<div class="legend right">
<div id="severity-legend"></div>
</div>
</div>
<div class="chart-notes">
Number of requests by Severity.
</div>
</div>
</div>
<div class="col-sm-12">
<div class="chart-wrapper">
<div class="chart-title">
Request Type
</div>
<div class="chart-stage">
<div class="chart">
<canvas id="requestTypeChart"></canvas>
</div>
</div>
<div class="chart-notes">
Number of requests by type.
</div>
</div>
</div>
<!-- TOOD: add a line chart showing requests by severtiy over time -->
<!--
<div class="col-sm-12">
<div class="chart-wrapper">
<div class="chart-title">
TODO: Requests Trends
<small class="pull-right">
<label class="pull-left" style="margin-right: 10px;">
In the last:
<select>
<option selected>Week</option>
<option>Month</option>
<option>Year</option>
</select>
</label>
</small>
</div>
<div class="chart-stage">
<div id="chart-05"></div>
</div>
<div class="chart-notes">
Trends in the number of requests over time.
</div>
</div>
</div>
-->
</div>
</div>
<div class="col-sm-6">
<div class="chart-wrapper">
<div class="chart-title">
Request Map
</div>
<div class="map-stage">
<div id="map"></div>
</div>
<div class="chart-notes">
Map of citzen request locations.
</div>
</div>
</div>
</div>
<p class="small text-muted">Built by <a href="https://esri.github.io/">Esri</a> with much ♥ to <a href="https://keen.io">Keen IO</a></p>
</div>
<!-- UI Resources -->
<!-- jQuery (for Bootstrap's JavaScript plugins). NOTE: You can also use pure Dojo. See examples. -->
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
<!-- Include all plugins or individual files as needed -->
<script src="//netdna.bootstrapcdn.com/bootstrap/3.2.0/js/bootstrap.min.js"></script>
<!-- Esri rocks -->
<script type="text/javascript">
window.dojoConfig = {
packages: [{
name: 'bootstrap-map',
location: '//esri.github.com/bootstrap-map-js/src/js'
}, {
name: 'chartjs',
location: '//www.chartjs.org/assets'
}]
};
</script>
<script src="//js.arcgis.com/3.11compact"></script>
<script>
require([
'esri/layers/FeatureLayer',
'esri/InfoTemplate',
'bootstrap-map/bootstrapmap',
'chartjs/Chart',
'dojo/domReady!'
], function(FeatureLayer, InfoTemplate, BootstrapMap, Chart) {
var severityChart, // pie chart
requestTypeChart; // bar chart
var citizenRequestLayerUrl = 'http://sampleserver5.arcgisonline.com/ArcGIS/rest/services/LocalGovernment/CitizenRequests/FeatureServer/0';
// TODO: get these from the feature layer on load
var severityFieldDomainCodedValuesDict = {
'0': 'General Nuisance',
'1': 'Important To Resolve Soon',
'2': 'Critical Issue'
};
var requestTypeFieldDomainCodedValuesDict = {
'0': 'Abandoned Vehicle',
'1': 'Animal Services',
'2': 'Driveway Infraction',
'3': 'Flooding',
'4': 'Graffiti Removal',
'5': 'Homeless Nuisance',
'6': 'Illegal Dumping',
'7': 'Parking Violation',
'8': 'Plant/Tree Complaint',
'9': 'Pothole Obstruction',
'10': 'Roadway Danger',
'11': 'Sidewalk Danger',
'12': 'Streetlight Broken',
'13': 'Street Sign Missing/Damaged',
'14': 'Trash Removal',
'15': 'Water Leak',
'16': 'Yard Waste Removal'
};
// override chart defaults
Chart.defaults.global.responsive = true;
Chart.defaults.global.maintainAspectRatio = false;
// kick off the application
initMap();
// initialize map and wire it up to the charts
function initMap() {
// create responsive map
var map = BootstrapMap.create('map', {
basemap:'topo',
center:[-117.1825, 34.0547],
zoom:14
});
// set up feature layer popup
var featureLayerInfoTemplate = new InfoTemplate();
featureLayerInfoTemplate.setTitle('<b>Request ${objectid}</b>');
var infoTemplateContent = '<span class="infoTemplateContentRowLabel">Date: </span>' +
'<span class="infoTemplateContentRowItem">${requestdate:DateFormat}</span><br><span class="infoTemplateContentRowLabel">Phone: </span>' +
'<span class="infoTemplateContentRowItem">${phone:formatPhoneNumber}</span><br><span class="infoTemplateContentRowLabel">Name: </span>' +
'<span class="infoTemplateContentRowItem">${name}</span><br><span class="infoTemplateContentRowLabel">Severity: </span>' +
'<span class="infoTemplateContentRowItem">${severity:severityDomainLookup}</span><br><span class="infoTemplateContentRowLabel">Type: </span>' +
'<span class="infoTemplateContentRowItem">${requesttype:requestTypeDomainLookup}</span><br><span class="infoTemplateContentRowLabel">Comments: </span>' +
'<span class="infoTemplateContentRowItem">${comment}</span>';
featureLayerInfoTemplate.setContent(infoTemplateContent);
// NOTE: popup formatting functions must be globals
window.severityDomainLookup = function (value, key, data){
return severityFieldDomainCodedValuesDict[value];
};
window.requestTypeDomainLookup = function (value, key, data){
return requestTypeFieldDomainCodedValuesDict[value];
};
window.formatPhoneNumber = function (value, key, data){
return value ? '<a href=\'tel:' + value + '\'>' + value + '</a>' : '';
};
var citizenRequestLayer = new FeatureLayer(citizenRequestLayerUrl, {
mode: FeatureLayer.MODE_ONEDEMAND,
infoTemplate: featureLayerInfoTemplate,
outFields: ['*']
});
citizenRequestLayer.on('update-end', function(layer) {
// update charts when feature layer is refreshed
// (i.e. after map pan/zoom)
updateCharts(citizenRequestLayer, map.extent);
});
map.addLayer(citizenRequestLayer);
}
// refresh chart based on feature layer stats
function updateCharts(featureLayer, extent) {
// get stats for feature layer
var stats = getGraphicsStats(featureLayer.graphics, ['severity', 'requesttype'], extent);
// create or update severity chart
updateSeverityChart(stats.severity.counts);
// create or update request type chart
updateRequestTypeChart(stats.requesttype.counts);
}
// get stats for each group by field
// TODO: currently only gets counts
// could aslo be configured to get the sum, etc
function getGraphicsStats(graphics, groupByFields, extent) {
var stats = {};
if (!groupByFields || !groupByFields.forEach) {
return;
}
groupByFields.forEach(function(groupByField) {
stats[groupByField] = getFieldStats(graphics, groupByField, extent);
});
return stats;
}
// get stats for a group by field
// TODO: currently only gets counts
// could aslo be configured to get the sum, etc
function getFieldStats(graphics, groupByField, extent) {
var total = 0;
var fieldCounts = {};
graphics.forEach(function(graphic) {
// exclude this graphic if it's not in the extent
if (!extent.contains(graphic.geometry)) {
return;
}
total = total + 1;
var fieldValue = graphic.attributes[groupByField];
var valueCount = fieldCounts[fieldValue];
if (!isNaN(valueCount)) {
fieldCounts[fieldValue] = valueCount + 1;
} else {
fieldCounts[fieldValue] = 1;
}
});
return {
total: total,
counts: fieldCounts
};
}
function updateSeverityChart(counts) {
// create severity chart data;
var segments = {
'0': {
color: '#46BFBD',
highlight: '#5AD3D1',
label: 'General Nuisance'
},
'1': {
color: '#FDB45C',
highlight: '#FFC870',
label: 'Important To Resolve Soon'
},
'2': {
color:'#F7464A',
highlight: '#FF5A5E',
label: 'Critical Issue'
}
};
var data = [];
for (var key in segments) {
if (segments.hasOwnProperty(key) && counts.hasOwnProperty(key)) {
var segment = segments[key];
segment.value = counts[key];
data.push(segment);
}
}
// create or update chart
if (severityChart) {
severityChart.destroy();
}
var ctx = document.getElementById('severity-chart').getContext('2d');
severityChart = new Chart(ctx).Pie(data, {
legendTemplate : '<ul class="<%=name.toLowerCase()%>-legend"><% for (var i=0; i<segments.length; i++){%><li><span style="background-color:<%=segments[i].fillColor%>"></span><%if(segments[i].label){%><%=segments[i].label%><%}%>: <%=segments[i].value%></li><%}%></ul>'
});
// update legend
var legend = severityChart.generateLegend();
document.getElementById('severity-legend').innerHTML = legend;
}
function updateRequestTypeChart(counts) {
// create reuest type chart data;
var data = {
labels: ['Abandoned Vehicle','Animal Services','Driveway Infraction','Flooding','Graffiti Removal','Homeless Nuisance','Illegal Dumping','Parking Violation','Plant/Tree Complaint','Pothole Obstruction','Roadway Danger','Sidewalk Danger','Streetlight Broken','Street Sign Missing/Damaged','Trash Removal','Water Leak','Yard Waste Removal'],
datasets: [
{
label: 'Request Types',
fillColor: 'rgba(151,187,205,0.5)',
strokeColor: 'rgba(151,187,205,0.8)',
highlightFill: 'rgba(151,187,205,0.75)',
highlightStroke: 'rgba(151,187,205,1)'
}
]
};
var datasetData = [];
data.labels.forEach(function(label, index) {
var count = counts[index] || 0;
datasetData.push(count);
});
data.datasets[0].data = datasetData;
if (requestTypeChart) {
requestTypeChart.destroy();
}
var options = {};
var ctx = document.getElementById('requestTypeChart').getContext('2d');
requestTypeChart = new Chart(ctx).Bar(data, options);
}
});
</script>
</body>
</html>