/
index.html
113 lines (87 loc) · 2.86 KB
/
index.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
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN">
<html>
<head>
<script src="http://d3js.org/d3.v2.js" type="text/javascript">
</script>
<style type="text/css">
body {
font: 10px sans-serif;
}
rect {
fill: steelblue;
stroke: white;
}
line {
stroke: black;
shape-rendering: crispEdges;
}
</style>
<title></title>
</head>
<body>
<script type="text/javascript">
function makeHistogram(data, width, height, color) {
var histogram = d3.layout.histogram()(data);
var x = d3.scale.ordinal()
.domain(histogram.map(function(d) { return d.x; }))
.rangeRoundBands([0, width]);
var y = d3.scale.linear()
.domain([0, d3.max(histogram.map(function(d) { return d.y; }))])
.range([0, height]);
var svg = d3.select("body").append("svg")
.attr("width", width)
.attr("height", height);
var rules = svg.append("g");
svg.selectAll("rect")
.data(histogram)
.enter().append("rect")
.attr("style", "fill:"+color)
.attr("width", x.rangeBand())
.attr("x", function(d) { return x(d.x); })
.attr("y", function(d) { return height - y(d.y); })
.attr("height", function(d) { return y(d.y); });
svg.append("line")
.attr("x1", 0)
.attr("x2", width)
.attr("y1", height)
.attr("y2", height);
var age1 = d3.max(data, function(d) { return d.age; }),
year0 = d3.min(data, function(d) { return d.year; }),
year1 = d3.max(data, function(d) { return d.year; }),
year = year1;
// Add rules to show the population values.
rules = rules.selectAll(".rule")
.data(y.ticks(10))
.enter().append("g")
.attr("class", "rule")
.attr("transform", function(d) { return "translate(0," + y(d) + ")"; });
rules.append("line")
.attr("x2", width);
rules.append("text")
.attr("x", 6)
.attr("dy", ".35em")
.attr("transform", "rotate(180)")
.text(function(d) { return Math.round(d / 1e6) + "M"; });
// Add labels to show the age.
svg.append("g").selectAll("text")
.data(d3.range(0, age1 + 5, 5))
.enter().append("text")
.attr("text-anchor", "middle")
.attr("transform", function(d) { return "translate(" + (x(d) + x(5) / 2) + ",-4)scale(-1,-1)"; })
.attr("dy", ".71em")
.text(String);
}
var lat = [], lon = [], alt = [];
d3.csv("/data/openpaths_jatorre.csv", function(csv){
csv.map(function(d) {
lat.push(d.lat);
lon.push(d.lon);
alt.push(d.alt);
});
makeHistogram(lat, 400, 300, '#86FF47');
makeHistogram(lon, 400, 300, '#FF8C38');
makeHistogram(alt, 400, 300, '#4F7DFF');
});
</script>
</body>
</html>