-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathfocus-view.html
121 lines (94 loc) · 3.91 KB
/
focus-view.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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>SOEditViz</title>
<link rel="stylesheet" type="text/css" href="global.css"/>
<script src="lib/d3/d3.min.js"></script>
<script src="global.js"></script>
</head>
<body>
<div class="header">
<label for="event_id">Event ID: </label>
<input type="number" id="event_id" disabled/>
<div class="divider"></div>
<label for="interval">Interval (hours): </label>
<input type="number" id="interval" class="interval"/>
<button type="button" id="update">Update</button>
</div>
<svg></svg>
<script>
var gridWidth = 5;
var gridStep = 60;
var queryParameters = [];
var updateButton = d3.select("#update");
// read query parameters
window.location.search.substr(1).split("&").forEach(function(keyValueString) {
var keyValue = keyValueString.split("=");
queryParameters[keyValue[0]] = keyValue[1];
});
if (!Object.keys(queryParameters).includes("postId") || !Object.keys(queryParameters).includes("eventId")) {
errorMessage("Query parameter postId or eventId is missing.");
}
var postId = parseInt(queryParameters["postId"]);
var eventId = parseInt(queryParameters["eventId"]);
// set event id
document.getElementById("event_id").value = eventId;
// set default offset
var interval = 24; // default interval is 24 hours
document.getElementById("interval").value = interval;
// register event handlers
updateButton.on("click", function() {
interval = parseInt(document.getElementById("interval").value);
updateView(interval);
});
updateView(interval);
function updateView(interval) {
clearSVG();
// read data and update view
readCSV(postId, function(data) {
var event = data.find(function(row) { return row.EventId === eventId; });
if (event == null) {
errorMessage("Event not found.");
}
// retrieve posts and assign index (question has always index 0, answers index >0)
var posts = retrievePosts(data);
// retrieve question id
var questionId = retrieveQuestionId(data);
// filter events
var minute = 60000;
var hour = 60 * minute;
var minTimestamp = event.CreationDate.getTime() - (interval/2)*hour;
var maxTimestamp = event.CreationDate.getTime() + (interval/2)*hour;
data = data.filter(
function(row) {
return row.CreationDate.getTime() >= minTimestamp
&& row.CreationDate.getTime() <= maxTimestamp;
}
);
// filter posts
var filteredPostIds = data.map(function(event) { return event.PostId; }).filter(onlyUnique);
// retrieve timestamps for x axis
minTimestamp = data[0].CreationDate.getTime();
maxTimestamp = data[data.length-1].CreationDate.getTime();
var timestamps = [];
for (var i = minTimestamp-minute; i <= maxTimestamp+minute; i+=minute) {
timestamps.push(getTimestampsDateAndTime(i));
}
// configure svg element
var maxX = gridAxisWidth + timestamps.length * gridWidth;
var maxY = Object.keys(posts).length * gridHeight;
configureSVG(maxX, maxY);
var group = d3.select("#mainGroup");
drawGrid(group, timestamps, maxY, gridWidth, gridStep);
drawYAxis(group, posts, filteredPostIds);
drawXAxis(group, timestamps, maxY, gridWidth, gridStep);
var coordinates = getCoordinatesContinuous(data, posts, timestamps);
drawPolyLine(group, coordinates, gridWidth);
drawDataPoints(group, coordinates, posts, questionId, gridWidth, false, null, false);
highlightEvent(eventId);
});
}
</script>
</body>
</html>