-
Notifications
You must be signed in to change notification settings - Fork 0
/
analytics.html
348 lines (301 loc) · 14.9 KB
/
analytics.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
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
<!DOCTYPE html>
<html>
<head>
<title>Analytics</title>
<link rel="stylesheet" href="css/style.css" />
<meta name="viewport" content="initial-scale=1.0, user-scalable=no"/>
<script type="text/javascript" src="http://maps.google.com/maps/api/js?sensor=true"></script>
<script type="text/javascript" src="http://mbostock.github.com/d3/d3.v2.min.js"></script>
<link rel="stylesheet" href="http://mbostock.github.com/d3/ex/colorbrewer.css">
<style type="text/css">
html, body, #map {
width: 100%;
height: 600px;
margin: 0;
padding: 0;
background-color: #FFFFFF;
}
.stations {
position: absolute;
}
.stations, .stations svg.aaa {
position: absolute;
}
.stations border {
position: absolute;
stroke: black;
stroke-width: 2px;
}
.stations svg.aaa {
width: 60px;
height: 20px;
padding-right: 100px;
font: 10px sans-serif;
}
.stations circle {
fill: red;
stroke: black;
stroke-width: 1.5px;
}
.axis path, .axis line {
fill: none;
stroke: #000;
shape-rendering: crispEdges;
}
text {
font: 10px sans-serif;
}
form {
position: absolute;
right: 10px;
top: 10px;
}
#breakdown {
margin: auto;
position: relative;
width: 960px;
}
</style>
</head>
<div id="head" style="background-color:#39578B; color:white; text-align:center; padding: 3px;">
<header><h2><strong>Problems Trending on Campus</strong></h2></header>
</div>
<body>
<div style="background-color:#FFFFFF; margin: auto; position: relative; width: 1300px;">
<div id="map"></div>
<script type="text/javascript">
// create map
var map = new google.maps.Map(d3.select("#map").node(), {
zoom: 16,
center: new google.maps.LatLng(38.986333, -76.940308),
mapTypeId: google.maps.MapTypeId.ROADMAP
});
var jsonString =
'[{"lat": 38.98358611111111, "type": "Plumbing", "lng": -76.94084166666667}, {"lat": 38.98353888888889, "type": "Electrical", "lng": -76.94335277777778}, {"lat": 38.983561111111115, "type": "Plumbing", "lng": -76.94345}, {"lat": 38.98336388888889, "type": "Plumbing", "lng": -76.94344444444445}, {"lat": 38.98856111111111, "type": "Security Concern", "lng": -76.94024722222223}, {"lat": 38.98857777777778, "type": "Security Concern", "lng": -76.93976666666667}, {"lat": 38.98845277777778, "type": "Furniture/Fixtures", "lng": -76.93972777777778}, {"lat": 38.98625277777778, "type": "Electrical", "lng": -76.93929166666668}, {"lat": 38.98952222222222, "type": "Plumbing", "lng": -76.94029166666667}, {"lat": 38.98925, "type": "Miscellanious", "lng": -76.94010833333334}, {"lat": 38.983336111111115, "type": "Security Concern", "lng": -76.94489166666666}, {"lat": 38.986272222222226, "type": "Furniture/Fixtures", "lng": -76.94532777777778}, {"lat": 38.98616666666667, "type": "Electrical", "lng": -76.944725}, {"lat": 38.99357222222222, "type": "Miscellanious", "lng": -76.94985277777778}, {"lat": 38.991847222222226, "type": "Miscellanious", "lng": -76.94702777777778}, {"lat": 38.991416666666666, "type": "Electrical", "lng": -76.94446666666667}, {"lat": null, "type": "Security Concern", "lng": null}, {"lat": 38.989802777777776, "type": "Electrical", "lng": -76.93741666666666}, {"lat": 38.98965555555556, "type": "Security Concern", "lng": -76.93655277777778}, {"lat": 38.989934, "type": "Electrical", "lng": -76.936065}, {"location": "Cumberland Hall", "type": "Plumbing"}, {"location": "Cumberland Hall", "type": "Electrical"}, {"location": "Washington Hall", "type": "Plumbing"}, {"location": "Cumberland Hall", "type": "Plumbing"}, {"location": "Hagerstown", "type": "Security Concern"}, {"location": "Hagerstown", "type": "Security Concern"}, {"location": "Hagerstown", "type": "Furniture/Fixtures"}, {"location": "Hagerstown", "type": "Electrical"}, {"location": "Hagerstown", "type": "Plumbing"}, {"location": "Hagerstown", "type": "Miscellanious"}, {"location": "Hagerstown", "type": "Security Concern"}, {"location": "Washington Hall", "type": "Security Concern"}, {"location": "Washington Hall", "type": "Furniture/Fixtures"}, {"location": "Washington Hall", "type": "Electrical"}, {"location": "Washington Hall", "type": "Miscellanious"}, {"location": "Washington Hall", "type": "Miscellanious"}, {"location": "Washington Hall", "type": "Electrical"}, {"location": null, "type": "Security Concern"}, {"location": "Washington Hall", "type": "Electrical"}, {"location": "Washington Hall", "type": "Security Concern"}]';
var data = JSON.parse(jsonString);
var locationTally = [];
var typeTally = [];
var gpsPoints = [];
data.forEach(function(node){
if (node.location){
if (!locationTally["\"" + node.location + "\""])
locationTally["\"" + node.location + "\""] = 1;
else
locationTally["\"" + node.location + "\""]+=1;
}
if (node.type){
if (!typeTally["\"" + node.type + "\""])
typeTally["\"" + node.type + "\""] = 1;
else
typeTally["\"" + node.type + "\""]+=1;
}
if (node.lat){
gpsPoints.push(node);
}
});
console.log(locationTally);
console.log(typeTally);
console.log(gpsPoints);
// Load the station data. When the data comes back, create an overlay.
var overlay = new google.maps.OverlayView();
// Add the container when the overlay is added to the map.
overlay.onAdd = function() {
var layer = d3.select(this.getPanes().overlayLayer).append("div")
.attr("height", "100%")
.attr("width", "100%")
.attr("class", "stations")
.attr("id", "layer");
layer[0][0].style.width = "1366px";
layer[0][0].parentNode.style.width = "100%";
layer[0][0].parentNode.style.height = "100%";
layer[0][0].parentNode.parentNode.style.width = "100%";
layer[0][0].parentNode.parentNode.style.height = "100%";
layer[0][0].parentNode.parentNode.parentNode.style.width = "100%";
layer[0][0].parentNode.parentNode.parentNode.style.height = "100%";
layer[0][0].parentNode.parentNode.parentNode.parentNode.style.width = "100%";
layer[0][0].parentNode.parentNode.parentNode.parentNode.style.height = "100%";
// Draw each marker as a separate SVG element.
// We could use a single SVG, but what size would it have?
overlay.draw = function() {
/*{"pt13": {"lat": 38.98358611111111, "type": "Plumbing", "log:": -76.94084166666667}, "pt12": {"lat": 38.98353888888889, "type": "Electrical", "log:": -76.94335277777778}, "pt11": {"lat": 38.983561111111115, "type": "Plumbing", "log:": -76.94345}, "pt10": {"lat": 38.98336388888889, "type": "Plumbing", "log:": -76.94344444444445}, "pt17": {"lat": 38.98856111111111, "type": "Security Concern", "log:": -76.94024722222223}, "pt16": {"lat": 38.98857777777778, "type": "Security Concern", "log:": -76.93976666666667}, "pt15": {"lat": 38.98845277777778, "type": "Furniture/Fixtures", "log:": -76.93972777777778}, "pt14": {"lat": 38.98625277777778, "type": "Electrical", "log:": -76.93929166666668}, "pt19": {"lat": 38.98952222222222, "type": "Plumbing", "log:": -76.94029166666667}, "pt18": {"lat": 38.98925, "type": "Miscellanious", "log:": -76.94010833333334}, "pt20": {"lat": 38.98999444444445, "type": "Security Concern", "log:": -76.93613333333333}, "pt9": {"lat": 38.983336111111115, "type": "Security Concern", "log:": -76.94489166666666}, "pt8": {"lat": 38.986272222222226, "type": "Furniture/Fixtures", "log:": -76.94532777777778}, "pt7": {"lat": 38.98616666666667, "type": "Electrical", "log:": -76.944725}, "pt6": {"lat": 38.99357222222222, "type": "Miscellanious", "log:": -76.94985277777778}, "pt5": {"lat": 38.991847222222226, "type": "Miscellanious", "log:": -76.94702777777778}, "pt4": {"lat": 38.991416666666666, "type": "Electrical", "log:": -76.94446666666667}, "pt3": {"lat": null, "type": "Security Concern", "log:": null}, "pt2": {"lat": 38.989802777777776, "type": "Electrical", "log:": -76.93741666666666}, "pt1": {"lat": 38.98965555555556, "type": "Security Concern", "log:": -76.93655277777778}}*/
var projection = this.getProjection(),
padding = 10;
var marker = layer.selectAll("svg")
.data(data)
.each(transform) // update existing markers
.enter().append("svg:svg")
.each(transform)
.attr("class", "marker aaa");
var radius = 5.0; // vary the size of the circles base on # of incident reports
marker.append("svg:circle")
.attr("r", radius)
.attr("cx", padding )
.attr("cy", padding );
// add a label.
marker.append("svg:text")
.attr("x", padding + 7)
.attr("y", padding)
.attr("dy", ".31em")
.text( function(d) {
return d.type; }
);
var v = d3.geom.voronoi( translate(gpsPoints) );
console.log( "v is :" );
console.log( v );
function translate(data) {
var d = []
for( var i=0; i<data.length; i++){
var c = [ data[i].lat, data[i].lng ]
d.push( c )
}
return d
}
function _projection( lat, lng ) {
e = new google.maps.LatLng( lat, lng );
e = projection.fromLatLngToDivPixel(e);
return [ e.x - padding, e.y - padding]
// return [ e.x, e.y ]
}
function transform(d) {
e = _projection( d.lat, d.lng )
console.log("marker " + d.lat +', ' + d.lng + " -> left: " + e[0] +", top: " + e[1] )
return d3.select(this)
.style("left", e[0] + "px")
.style("top", e[1] + "px");
}
function transform_path(data) {
var d = []
console.log(data)
for( var i=0; i<data.length; i++) {
var c = _projection( data[i][0], data[i][1] )
console.log( ' path point: ' + JSON.stringify(data[i]) + ' -> left: ' + c[0] + ", top: " + c[1])
d.push( c )
}
// console.log(d)
return d
}
};
};
// Bind our overlay to the map…
overlay.setMap(map);
</script>
<h2 style="text-align:center; background-color: #B0C3DC; padding: 10px; color:black;">Problem Occurence Over Time</h2>
<div id="breakdown">
<form>
<label>
<input type="radio" name="mode" value="grouped">
Grouped</label>
<label>
<input type="radio" name="mode" value="stacked" checked>
Stacked</label>
</form>
<script src="http://d3js.org/d3.v3.min.js"></script>
<script>
var n = 4, // number of layers
m = 58, // number of samples per layer
stack = d3.layout.stack(),
layers = stack(d3.range(n).map(function() { return bumpLayer(m, .1); })),
yGroupMax = d3.max(layers, function(layer) { return d3.max(layer, function(d) { return d.y; }); }),
yStackMax = d3.max(layers, function(layer) { return d3.max(layer, function(d) { return d.y0 + d.y; }); });
var margin = {top: 40, right: 10, bottom: 20, left: 10},
width = 960 - margin.left - margin.right,
height = 500 - margin.top - margin.bottom;
var x = d3.scale.ordinal()
.domain(d3.range(m))
.rangeRoundBands([0, width], .08);
var y = d3.scale.linear()
.domain([0, yStackMax])
.range([height, 0]);
var color = d3.scale.linear()
.domain([0, n - 1])
.range(["#aad", "#556"]);
var xAxis = d3.svg.axis()
.scale(x)
.tickSize(0)
.tickPadding(6)
.orient("bottom");
var svg = d3.select("#breakdown").append("svg")
.attr("width", width + margin.left + margin.right)
.attr("height", height + margin.top + margin.bottom)
.append("g")
.attr("transform", "translate(" + margin.left + "," + margin.top + ")");
var layer = svg.selectAll(".layer")
.data(layers)
.enter().append("g")
.attr("class", "layer")
.style("fill", function(d, i) { return color(i); });
var rect = layer.selectAll("rect")
.data(function(d) { return d; })
.enter().append("rect")
.attr("x", function(d) { return x(d.x); })
.attr("y", height)
.attr("width", x.rangeBand())
.attr("height", 0);
rect.transition()
.delay(function(d, i) { return i * 10; })
.attr("y", function(d) { return y(d.y0 + d.y); })
.attr("height", function(d) { return y(d.y0) - y(d.y0 + d.y); });
svg.append("g")
.attr("class", "x axis")
.attr("transform", "translate(0," + height + ")")
.call(xAxis);
d3.selectAll("input").on("change", change);
var timeout = setTimeout(function() {
d3.select("input[value=\"grouped\"]").property("checked", true).each(change);
}, 2000);
function change() {
clearTimeout(timeout);
if (this.value === "grouped") transitionGrouped();
else transitionStacked();
}
function transitionGrouped() {
y.domain([0, yGroupMax]);
rect.transition()
.duration(500)
.delay(function(d, i) { return i * 10; })
.attr("x", function(d, i, j) { return x(d.x) + x.rangeBand() / n * j; })
.attr("width", x.rangeBand() / n)
.transition()
.attr("y", function(d) { return y(d.y); })
.attr("height", function(d) { return height - y(d.y); });
}
function transitionStacked() {
y.domain([0, yStackMax]);
rect.transition()
.duration(500)
.delay(function(d, i) { return i * 10; })
.attr("y", function(d) { return y(d.y0 + d.y); })
.attr("height", function(d) { return y(d.y0) - y(d.y0 + d.y); })
.transition()
.attr("x", function(d) { return x(d.x); })
.attr("width", x.rangeBand());
}
// Inspired by Lee Byron's test data generator.
function bumpLayer(n, o) {
function bump(a) {
var x = 1 / (.1 + Math.random()),
y = 2 * Math.random() - .5,
z = 10 / (.1 + Math.random());
for (var i = 0; i < n; i++) {
var w = (i / n - y) * z;
a[i] += x * Math.exp(-w * w);
}
}
var a = [], i;
for (i = 0; i < n; ++i) a[i] = o + o * Math.random();
for (i = 0; i < 5; ++i) bump(a);
return a.map(function(d, i) { return {x: i, y: Math.max(0, d)}; });
}
</script>
<p style="text-align:center;">Frequency of Reports per Day</p>
</div>
</div>
<div style="margin: 0 auto; text-align: center;">
<a class="twitter-timeline" href="https://twitter.com/hashtag/umd4work" data-widget-id="511131876757495809">#umd4work Tweets</a>
<script>!function(d,s,id){var js,fjs=d.getElementsByTagName(s)[0],p=/^http:/.test(d.location)?'http':'https';if(!d.getElementById(id)){js=d.createElement(s);js.id=id;js.src=p+"://platform.twitter.com/widgets.js";fjs.parentNode.insertBefore(js,fjs);}}(document,"script","twitter-wjs");</script>
</div>
</body>
<footer style="background:#292F3E; text-align: center; padding:8px;">
<div style="padding:15px;">Back To Main</div>
<a href="index.html"><img src="images/sustain.jpg" style="width:50px; border-radius:25px;"></a> </footer>
</html>