-
Notifications
You must be signed in to change notification settings - Fork 7
/
timeline.html
136 lines (118 loc) · 3.6 KB
/
timeline.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
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<script src="https://cdnjs.cloudflare.com/ajax/libs/d3/3.5.5/d3.min.js" charset="utf-8"></script>
<script src="pings2.json"></script>
<script>
function tabulate(data, columns) {
var table = d3.select("body").append("table"),
thead = table.append("thead"),
tbody = table.append("tbody");
// append the header row
thead.append("tr")
.selectAll("th")
.data(columns)
.enter()
.append("th")
.text(function(column) { return column; });
// create a row for each object in the data
var rows = tbody.selectAll("tr")
.data(data)
.enter()
.append("tr");
// create a cell in each row for each column
var cells = rows.selectAll("td")
.data(function(row) {
return columns.map(function(column) {
return {column: column, value: row[column]};
});
})
.enter()
.append("td")
.attr("style", "font-family: Courier")
.html(function(d) { return d.value; });
return table;
}
function uniq(a) {
return a.sort().filter(function(item, pos, ary) {
return !pos || item != ary[pos - 1];
});
}
var startDate = new Date(2015, 2, 1);
var endDate = new Date(2015, 4, 6);
var format = d3.time.format('%Y%m%dT%H%M%S.%LZ');
function hourIndex(dt) {
var hi = Math.floor((dt.getTime() - startDate.getTime()) / (1000 * 3600));
if (hi < 0) {
console.log(dt);
}
return hi;
}
/* Parse timestamps */
for (var icao in pings) {
pings[icao].pings = pings[icao].pings.map(function(ping) {
ping.timestamp = format.parse(ping.timestamp);
ping.hourIndex = hourIndex(ping.timestamp);
return ping;
});
}
function plotHours(data, options) {
options = options || {};
var width = options.width || 200;
var height = options.height || 10000;
var barWidth = options.barWidth || 200;
var index = options.index || 0;
console.log(data.length + " hours");
console.log(index);
console.log(data);
var x = d3.scale.linear()
.domain([0, hourIndex(endDate) + 1])
.range([0, height]);
var chart = d3.select(".chart")
.attr("width", 800)
.attr("height", height);
var t = "translate(" + barWidth * index + "," + x(data[0]) + ")";
console.log(t);
var bar = chart.selectAll(".idx" + index)
.data(data)
.enter().append("g")
.attr("transform", function(d, i) { return "translate(" + barWidth * index + "," + x(d) + ")"; });
bar.append("rect")
.attr("width", barWidth)
.attr("height", x(1));
}
function pingsToHourIndices(pings) {
var hourIndices = uniq(pings.map(function(d) { return d.hourIndex; }));
hourIndices.sort(function(a, b) { return a - b; });
return hourIndices;
}
function plotPings(pings, options) {
var hourIndices = pingsToHourIndices(pings);
plotHours(hourIndices, options);
}
</script>
<title>Suspected FBI surveillance aircraft flight timelines, Los Angeles</title>
</head>
<body>
<h1>Suspected FBI surveillance aircraft flight timelines, Los Angeles</h1>
<script>
var aircraftInfos = [];
for (var icao in pings) {
aircraftInfos.push(pings[icao]);
}
tabulate(aircraftInfos, ["registration", "owner"]);
</script>
<svg class="chart"></svg>
<script>
var days = [];
for (var i = 0; i < hourIndex(endDate) + 1; i += 24) {
days.push(i);
}
plotHours(days, {index: 0});
plotPings(pings["A22AEF"].pings, {index: 1});
plotPings(pings["A4BC6E"].pings, {index: 2});
plotPings(pings["AD4B3C"].pings, {index: 3});
</script>
</body>
</html>