/
couplemap.html
543 lines (472 loc) · 23 KB
/
couplemap.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
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
<!DOCTYPE html>
<html>
<head>
<meta charset=utf-8/>
<title> Couple Map </title>
<!-- Styles -->
<link rel="stylesheet" href="http://cdn.leafletjs.com/leaflet-0.7.3/leaflet.css" />
<link rel="stylesheet" href = "assets/styles.css" />
<link rel = "stylesheet" href = "assets/foundation.css" />
<link href='http://fonts.googleapis.com/css?family=Open+Sans:300italic,400italic,600italic,700italic,800italic,400,300,600,700,800' rel='stylesheet' type='text/css'>
<link rel="stylesheet" href="https://ajax.googleapis.com/ajax/libs/jqueryui/1.11.3/themes/smoothness/jquery-ui.css">
<link rel="stylesheet" href="http://code.ionicframework.com/ionicons/1.5.2/css/ionicons.min.css">
<!-- External Scripts -->
<script src="http://cdn.leafletjs.com/leaflet-0.7.3/leaflet.js"></script>
<script src="http://code.jquery.com/jquery-1.10.2.min.js"></script>
<script src="http://d3js.org/d3.v3.min.js" type="text/javascript"></script>
<script src = "https://cdnjs.cloudflare.com/ajax/libs/moment.js/2.10.2/moment.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/foundation/5.5.2/js/foundation.js" type = "text/javascript"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/foundation/5.5.2/js/foundation/foundation.slider.js" type = "text/javascript"></script>
<script src= "https://cdnjs.cloudflare.com/ajax/libs/foundation/5.5.2/js/foundation/foundation.reveal.js" type="text/javascript"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/jqueryui/1.11.4/jquery-ui.min.js"></script>
<script src="assets/Leaflet.MakiMarkers.js"></script>
</head>
<body>
<!-- Modals - HTML -->
<a href="#" data-reveal-id="myModal" class = "helptext"> Help </a>
<a href="#" data-reveal-id="endingModal"></a>
<div id="endingModal" class="reveal-modal tiny" data-reveal aria-labelledby="modalTitle" aria-hidden="true" role="dialog" style = "background: transparent !important">
<div class = "endingmodalbox">
<div class = "center endingmodalbutton" id = "resetbtn2"> <a class = "close" aria-label="Close">Play map again</a></div>
<div class = "center endingmodalbutton"> <a href = "groups.html"> Return to groups </a></div>
</div>
</div>
<div id="myModal" class="reveal-modal small" data-reveal aria-labelledby="secondmodalTitle" aria-hidden="true" role="dialog">
<h2 id="secondmodalTitle"> Help Guide </h2>
<p class="lead"> This map displays a month's worth of real data. </p>
<p> Click the buttons on the left to <strong>play, pause, reset, or jump forward</strong> on the map. You can <strong>move the map around </strong>by holding down your mouse and dragging. </p>Learn more about the group and their data by hovering over the <strong>"Map Insights", "Conclusions", or "The Data" tabs.</strong>
<p> Click <a href = "groups.html">here</a> to return to the groups page, or use the navigation bar at the bottom right. </p>
<a class="close-reveal-modal" aria-label="Close">×</a>
</div>
<!-- Navigation Bar -->
<div class = "navbar">
<ul class = "navbar-list">
<li class = "navbar-item">
<a class = "navbar-link white" href = "about.html"> About </a>
</li>
<li class = "navbar-item">
<a class = "navbar-link white" href="groups.html"> The Groups </a>
</li>
<li class = "navbar-item">
<a class = "navbar-link white" href = "maps.html"> The Maps </a>
</li>
</ul>
</div>
<!-- Interface -->
<div id = "container">
<div id="map"></div>
</div>
<div id = "aboutbar">
<div class = "abouttext">
<strong>Story: Couple </strong></br>
</div>
<div id = "message"> </div>
<div class="row">
</div>
</div>
<div class = "controls">
<div class = "btn active" id = "playbtn">Play</div>
<div class = "btn" id = "pausebtn">Pause</div>
<div class = "btn" id = "resetbtn">Reset</div>
<div class = "btn" id = "jumptoend"> >> </div>
</div>
<div id = "seek">
<div class = "seekbarvalue white"></div>
<input type ="range" id="seekbar" value="0" />
</div>
<div id = "timebar">
<div id = "timevalue" class = "white"> </div>
</div>
<div class = "extrainformation">
<p class = "stats">
<div id = "flatmate1key"><div class ="keytext"> Person 1 (UK)</div></div>
<div id = "flatmate2key"><div class ="keytext">Person 2 (US) </div></div>
<!-- <div id = "flatmate3key"><div class ="keytext">Coworker 3</div></div> -->
</p>
</div>
<!-- "Learn More" Link and Content -->
<a href="#" data-dropdown="hover1" data-options="is_hover:true; hover_timeout:10000" class = "learnmore"> Map Insights </a>
<a href="#" data-dropdown="hover2" data-options="is_hover:true; hover_timeout:10000" class = "learnevenmore">Conclusions </a>
<a href="#" data-dropdown="hover3" data-options="is_hover:true; hover_timeout:10000" class = "learnthemost">The Data </a>
<div id="hover1" class="f-dropdown learnmorecontent tiny" data-dropdown-content>
<h3> How to Read the Map </h3>
<p> This map is zoomed out to reflect the literal distance that the two people in this relationship covered over the course of the month. In the time that they were tracked, the two made trips for both work and holiday. Collectively they visited at least five different countries. Though the two spend only a few days of the month together physically, you'll notice immediately that the number of messages that they exchange decreases once they're in one another's presences and increases as soon as they separate. </p>
</div>
<div id="hover2" class="f-dropdown learnmorecontent" data-dropdown-content>
<h3> The Questions of Long-Distance </h3>
<p> What does long-distance mean in a time where asynchronous multi-channel communication is the norm? I only kept track of this couple's messages (not their emails, phone calls, or snail mail), so this visualization represents a 21st-century reality. I could not have constructed a similar map for the long-distance relationship my parents had in the 1980s; similar message data wouldn't even have existed. </p>
<p> Do our many options for staying connected render "long-distance" an obsolete concept? Could distance allow the potential to learn more about yourself and your conversation habits? Does this couple's digital pattern of contact (chunks of writing and replying, suggesting conversations rather than isolated messages) mimic their offline ways of communicating? Do devices give us the space to communicate better, more intentionally?</p>
<p> Or are our online modes of communication mere shadows of the richer in-person alternatives? </p>
</div>
<div id="hover3" class="f-dropdown learnmorecontent" data-dropdown-content>
<h3> Dealing with the Data </h3>
<p> This couple's data was particularly tricky to work with. Part of this had to do with the constantly changing timezones that they moved through as they both traveled for work and holidays. For simplicity's sake, all of the times in this map are in GMT, or London's timezone, though they shifted through different ones. It also affects their location map, making it seem that they're further away from each other in the week that they spend together. </p>
<p> Another difficulty had to do with the metadata itself. Initially I gathered Skype data from the couple as well, but that didn't make it into the total count because of how messy the output was (it wasn't easy to reliably decipher the difference between missed, returned, and incoming calls). In the end, I elected to dismiss Skype since the tracking was centered around messages rather than calls anyway. </p>
</div>
<!-- // Map -->
<script type="text/javascript">
var initialTimestamp = 1426627072;
var initialTimestamp = 1426627572;
var color1 = "#0096FF"; // person 1
var color2 = "#FF5000"; // person 2
var maincolor = "#15295e";
var mainMap = setupMapObject( 39.472, 22.265, 3, 'greymap/{z}/{x}/{y}.png', 3, [color1, color2] );
var lineGenerator = d3.svg.line()
.interpolate("linear")
.x(function(d) {return applyLatLngToLayer(d).x})
.y(function(d) {return applyLatLngToLayer(d).y});
function setupMapObject(latitude, longitude, zoom, tileURL, maximumZoom, colors){
var map = L.map('map', {
attributionControl: false, zoomControl: false, minZoom: 2, maxZoom:3 })
.setView([latitude, longitude], zoom);
var tiles = L.tileLayer(tileURL, {
maxZoom: maximumZoom });
// minZoom: 10});
tiles.addTo(map);
var svg = d3.select(map.getPanes().overlayPane).append("svg");
var g1 = svg.append("g").attr();
var g2 = svg.append("g").attr();
var colors = colors;
return {
map: map,
tiles: tiles,
svg: svg,
g1: g1,
g2: g2,
colors: colors
};
}
function setSVGHeightAndWidth(geojsons, linepaths){
var transform = d3.geo.transform({
point: projectPoint
});
var d3path = d3.geo.path().projection(transform);
function projectPoint(x, y) {
var point = mainMap.map.latLngToLayerPoint(new L.LatLng(y, x));
this.stream.point(point.x, point.y);
}
var top, left, bottom, right;
var isFirstIteration = true;
$.each(geojsons, function (index){
var newBounds = d3path.bounds(geojsons[index]);
if (isFirstIteration) {
top = newBounds[0][1];
left = newBounds[0][0];
bottom = newBounds[1][1];
right = newBounds[1][0];
isFirstIteration = false;
} else {
if (newBounds[0][1] < top){
top = newBounds[0][1];
}
if (newBounds[0][0] < left){
left = newBounds[0][0];
}
if (newBounds[1][1] > bottom){
bottom = newBounds[1][1];
}
if (newBounds[1][0] > right){
right = newBounds[1][0];
}
}
});
mainMap.svg.attr("width", right - left)
.attr("height", bottom - top)
.style("left", left + "px")
.style("top", top + "px");
mainMap.g1.attr("transform", "translate(" + -left + "," + -top + ")");
mainMap.g2.attr("transform", "translate(" + -left + "," + -top + ")");
}
function makeColorClosure(){
var closureColorIndex = 0;
var closure = function () {
var color = mainMap.colors[closureColorIndex];
closureColorIndex = (closureColorIndex + 1) % mainMap.colors.length;
return color;
}
return closure;
}
function applyLatLngToLayer(d) {
var y = d.geometry.coordinates[1];
var x = d.geometry.coordinates[0];
return mainMap.map.latLngToLayerPoint(new L.LatLng(y, x))
}
var getColor = makeColorClosure();
function geojsonToLinepaths(g, data) {
features = data.map(function(d) {return d.pathCoords}); //list of lists of the features
var linepaths = g.selectAll("path")
.data(features)
.enter()
.append("path")
.attr("d", lineGenerator)
.attr("stroke", getColor)
.attr("stroke-width", 3)
.attr("stroke-linecap", "round")
.attr("stroke-opacity", .3)
.attr("fill-opacity", "0");
return linepaths;
}
function geojsonToHighlightedLinepaths(g, data) {
features = data.map(function(d) {return d.pathCoords}); //list of lists of the features
var linepaths = g.selectAll("path")
.data(features)
.enter()
.append("path")
.attr("d", lineGenerator)
.attr("stroke", getColor)
.attr("stroke-linecap", "round")
.attr("stroke-width", 13)
.attr("stroke-opacity", 1)
.attr("fill-opacity", "0")
.attr("class", getColor);
return linepaths;
}
function setupLinePaths(linepaths) {
linepaths.each(function(d){ d.totalLength = this.getTotalLength();})
.attr("stroke-dasharray", function(d){ return d.totalLength;})
.attr("stroke-dashoffset", function(d){return d.totalLength;});
}
function setupHighlightedLinePaths(highlightedLinepaths){
highlightedLinepaths.each(function(d) { d.totalLength = this.getTotalLength();})
.attr("stroke-dasharray", function(d){ return [1, d.totalLength];})
.attr("stroke-dashoffset", function(d){return d.totalLength;});
}
function drawMapAtTime(linepaths, geojsons, time){
// find fraction of journey completed, update linepath dashoffset
linepaths.each(function(d, i){
d.geojson = geojsons[i];
d.totalLength = this.getTotalLength();})
.attr("stroke-dashoffset", function(d) {return fractionOfJourneyCompleted(d.geojson,time) * d.totalLength + d.totalLength;})
console.log()
$( "#seekbar" ).val((time/worldState.maxtimestamp) * 100);
$(".seekbarvalue").html(formatCurrentDay(time)
);
// For showing the context messages
var eventCollection = [
{ starttime: 0, endtime: 10001 , message: '', textcolor: maincolor },
{ starttime: 14001, endtime: 96000 , message: '81 messages exchanged today', textcolor: maincolor },
{ starttime: 97001, endtime: 181001 , message: '42 messages exchanged today', textcolor: maincolor },
{ starttime: 183001, endtime: 271001 , message: '17 messages exchanged today', textcolor: maincolor },
{ starttime: 272001, endtime: 355001 , message: '42 messages exchanged today', textcolor: maincolor },
{ starttime: 358001, endtime: 442156 , message: '43 messages exchanged today', textcolor: maincolor },
{ starttime: 442256, endtime: 530057 , message: '147 messages exchanged today', textcolor: maincolor },
{ starttime: 530257, endtime: 615057 , message: '54 messages exchanged today', textcolor: maincolor },
{ starttime: 615257, endtime: 703057 , message: '176 messages exchanged today', textcolor: maincolor },
{ starttime: 703257, endtime: 788015 , message: '129 messages exchanged today', textcolor: maincolor },
{ starttime: 788215, endtime: 877015 , message: '147 messages exchanged today', textcolor: maincolor },
{ starttime: 877215, endtime: 960015 , message: '76 messages exchanged today', textcolor: maincolor },
{ starttime: 960215, endtime: 1044015 , message: '100 messages exchanged today', textcolor: maincolor },
{ starttime: 1044215, endtime: 1130015 , message: '8 messages exchanged today', textcolor: maincolor },
{ starttime: 1130215, endtime: 1187115 , message: '0 messages exchanged today', textcolor: maincolor },
{ starttime: 1187215, endtime: 1302506 , message: '0 messages exchanged today', textcolor: maincolor },
{ starttime: 1343215, endtime: 1388406 , message: '0 messages exchanged today', textcolor: maincolor },
{ starttime: 1388706, endtime: 1475506 , message: '0 messages exchanged today', textcolor: maincolor },
{ starttime: 1475706, endtime: 1562506 , message: '0 messages exchanged today', textcolor: maincolor },
{ starttime: 1562706, endtime: 1647430 , message: '6 messages exchanged today', textcolor: maincolor },
{ starttime: 1647730, endtime: 1747000 , message: '0 messages exchanged today', textcolor: maincolor },
{ starttime: 1747197, endtime: 1900000 , message: '7 messages exchanged today', textcolor: maincolor },
{ starttime: 1910000, endtime: 1997400 , message: '33 messages exchanged today', textcolor: maincolor },
{ starttime: 1997500, endtime: 2083000 , message: '55 messages exchanged today', textcolor: maincolor },
{ starttime: 2085000, endtime: 2166000 , message: '73 messages exchanged today', textcolor: maincolor },
{ starttime: 2167000, endtime: 2252000 , message: '173 messages exchanged today', textcolor: maincolor },
{ starttime: 2253000, endtime: 2341680 , message: '51 messages exchanged today', textcolor: maincolor },
{ starttime: 2341880, endtime: 2425480 , message: '285 messages exchanged today', textcolor: maincolor },
{ starttime: 2425880, endtime: 2513480 , message: '73 messages exchanged today', textcolor: maincolor },
{ starttime: 2513880, endtime: 2549274 , message: '146 messages exchanged today', textcolor: maincolor },
{ starttime: 2514242, endtime: 2549274 , message: '32 messages exchanged today', textcolor: maincolor },
{ starttime: 2514242, endtime: 2549274 , message: '82 messages exchanged today', textcolor: maincolor }
];
matchingEvents = [];
eventCollection.getEventsForTime = function(timestep) {
for (var x = 0; x < eventCollection.length; x++) {
if (timestep >= eventCollection[x].starttime && timestep <= eventCollection[x].endtime){
matchingEvents.push(eventCollection[x]);
}
} return matchingEvents;
}
var returnedEvents = eventCollection.getEventsForTime(time)
if (returnedEvents[0] && returnedEvents[0].textcolor && returnedEvents[0].message) {
var currentColor = returnedEvents[0].textcolor;
var currentMessage = returnedEvents[0].message; }
$("#message").css("color", currentColor);
return $("#message").html(currentMessage);
}
function fractionOfJourneyCompleted(geojson, time) {
var geojsonTimeValues = []
$.each(geojson.features, function(key, value){
geojsonTimeValues.push(geojson.features[key].properties.t)
answer = findClosestTimeValue(time, geojsonTimeValues);
correspondingIndex = geojsonTimeValues.indexOf(answer);
});
fractionValue = geojson.features[correspondingIndex].properties["total_distance"]/geojson.features[(geojsonTimeValues.length-1)].properties["total_distance"];
return fractionValue;
}
function findClosestTimeValue(number, array) {
var currentValue = array[0];
var difference = Math.abs(number - currentValue);
for (var value = 0; value < array.length; value++){
var newDifference = Math.abs(number - array[value]);
if (newDifference < difference){
difference = newDifference;
currentValue = array[value];
}
}
return currentValue;
}
function getAllGeoJsons(urls, callback) {
var results = [];
// introduce new scope to capture loop index
var loaded = function(i){
return function(data){
results[i] = data;
}
}
//Kick off requests to all files and store them in results
for (var i = 0; i < urls.length; i++){
var url = urls[i];
var dataIndex = i;
results.push(null);
d3.json(url, loaded(i));
}
timeoutFunc = function(){
var loaded = true;
// If no nulls, then we've finished loading.
for(var i = 0; i < results.length; i++){
if(results[i] == null){
loaded = false
}
}
if(loaded) {
callback(results);
} else {
setTimeout(timeoutFunc, 100);
}
};
setTimeout(timeoutFunc, 100) // check every 1/10 second if we have finished loading
}
function render(geojsons) {
mainMap.g1.selectAll("path").remove();
mainMap.g2.selectAll("path").remove();
var linepaths = geojsonToLinepaths(mainMap.g1, geojsons);
var highlightedLinepaths = geojsonToHighlightedLinepaths(mainMap.g2, geojsons);
setSVGHeightAndWidth(geojsons, highlightedLinepaths);
setupLinePaths(linepaths);
setupHighlightedLinePaths(highlightedLinepaths);
self = this;
setInterval(function(){
if (worldState.timestep < 2549274){
assignTimeValue();
linepaths.each(function(linepath, index){
if (index == 0) {
drawMapAtTime(linepaths,geojsons,self.timestep);
}
});
highlightedLinepaths.each(function(highlightedLinepath, index){
if (index == 0) {
drawMapAtTime(highlightedLinepaths,geojsons,self.timestep);
}
});
if(self.playing){
self.timestep += self.multiplier;
}
}
else {
$('#endingModal').foundation('reveal', 'open');
}
}, 100);
}
//Entry function that gets GeoJSON files, waits until all are loaded.
getAllGeoJsons(["Group4Data/person1_london.json", "Group4Data/person2_boston.json"], function(results) {
results.forEach(function(result){
result.pathCoords = result.features.slice();
result.pathCoords.reverse();
});
var timestamps = results.map(function(d) {return d.features.slice(-1)[0].properties.t });
worldState.maxtimestamp = Math.max.apply(null, timestamps);
worldState.render(results);
worldState.play();
mainMap.map.on("viewreset", function() { worldState.render(results) });
})
// Overlay Controls
$(document).foundation();
//Buttons
$("#playbtn").click(function(){
worldState.play();
$("#playbtn").addClass('active');
$("#pausebtn").removeClass('active');
$("#resetbtn").removeClass('active');
});
$("#pausebtn").click(function(){
worldState.pause();
$("#pausebtn").addClass('active');
$("#playbtn").removeClass('active');
$("#resetbtn").removeClass('active');
});
$("#resetbtn").click(function(){
worldState.reset();
worldState.timestep = 1;
});
$("#resetbtn2").click(function(){
worldState.reset();
worldState.timestep = 1;
});
$("#jumptoend").click(function(){
worldState.timestep = worldState.timestep + 200000 ;
});
// Timer
function formatTimestep() {
return moment.unix(worldState.timestep + initialTimestamp).format("dddd, MMM Do HH:mm");
}
function assignTimeValue() {
$("#timevalue").html(formatTimestep());
}
$(function() {
$( "#slider" ).slider();
});
// Seekbar
$( "#seekbar" ).on( "change", function() {
var sliderValue = $('#seekbar').val();
worldState.timestep = sliderValue * worldState.maxtimestamp * 0.01;
} );
//Day Indicator
function formatCurrentDay(currentTimestamp) {
var initialMoment = moment(initialTimestamp);
var offset = initialMoment.hours() * 3600 + initialMoment.minutes() * 60 + initialMoment.seconds();
var dayTimestamp = currentTimestamp - 9000;
return ("Day " + (moment.duration(dayTimestamp, "seconds").days() + 1) + " of 30");
}
// Modal Actions
$(document).on('opened.fndtn.reveal', '[data-reveal]', function () {
worldState.pause();
var modal = $(this);
});
$(document).on('closed.fndtn.reveal', '[data-reveal]', function () {
worldState.play();
var modal = $(this);
});
$('a.close').on('click', function() {
$('#endingModal').foundation('reveal', 'close');
});
// Top-level controls
var worldState = {
maxtimestamp: 0,
timestep: 1,
multiplier: 3000,
render: render,
playing: true,
play: function(){
this.playing = true;
},
pause: function(){
this.playing = false;
},
reset: function(){
worldState.timestep = 0;
},
changeSpeed: function(){
worldState.multiplier = realSliderValue[0] + worldState.multiplier;
}
};
</script>
</body>
</html>