-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.html
169 lines (135 loc) · 4.33 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
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
<!DOCTYPE html>
<meta charset="utf-8">
<script src="https://d3js.org/d3.v4.min.js"></script>
<title>The Planets of Star Wars, a Data-Driven Look</title>
<style>
body {
font-family: sans-serif;
}
span {
-webkit-text-stroke: 1px black;
font-weight: bold;
}
.group {
fill: none;
}
#intro {
width: 35%;
}
#container {
margin-top: -300px;
display: flex;
align-items: center;
}
#info {
float: left;
width: 25%;
text-align: right;
}
#vis {
float: left;
width: 75%;
}
footer {
text-align: right;
}
</style>
<body>
<div id="intro">
<h1>The Planets of Star Wars: A Data-Driven Look</h1>
<p>
To celebrate the upcoming release of Rogue One, we created a data-driven look of the planets in the Star Wars universe.
</p>
<p>
We adapted <a href="https://bl.ocks.org/mbostock/3007180">Mike Bostock's Exoplanets code</a>, and used data from <a href="http://starwarsgalaxy.co/">nclud's Star Wars Galaxy interactive.</a> The source is <a href="https://github.com/blrubenstein/star-wars-planets-data-vis">GitHub</a>.
</p>
<ul>
<li>Population is mapped from <span style="color:#B7A17E">Low</span> to <span style="color:#AD0E12">High</span>, with Unknown populations as <span>Black</span>.</li>
<li>Circle size is mapped from to planet size.</li>
<li>Some of the well-known planets are in the center ring.</li>
</ul>
</div>
</div>
<div id="container">
<div id="info">
</div>
<div id="vis">
</div>
</div>
<footer>
By <a href="http://www.linkedin.com/in/brianrubenstein3564b192">Brian Rubenstein</a>, <span style="color: black; font-weight: normal; -webkit-text-stroke: 0px black;">Bryan Benson</span>, and <a href="http://twitter.com/laneharrison">Lane Harrison</a>.
</footer>
<script src="https://d3js.org/d3.v4.min.js"></script>
<script>
var color = d3.scaleLog()
.range(["#B7A17E", "#AD0E12"])
.interpolate(d3.interpolateCubehelix.gamma(3));
var size = 960;
var pack = d3.pack()
.size([size, size])
.padding(25);
var svg = d3.select("#vis").append("svg")
.attr("width", size)
.attr("height", size);
d3.csv("swplanets.csv", type, function(error, data) {
var knownplanets = data.filter(function(d) { return d.known === 1; }),
outerplanets = data.filter(function(d) { return d.known === 0; });
color.domain(d3.extent(data, function(d) { return d.population ? d.population/1000 : 1; }));
var root = d3.hierarchy({children: [{children: knownplanets}].concat(outerplanets)})
.sum(function(d) { return d.size * d.size; })
.sort(function(a, b) {
return !a.children - !b.children
|| isNaN(a.data.size) - isNaN(b.data.size)
|| a.data.size - b.data.size;
});
pack(root);
svg.selectAll("circle")
.data(root.descendants().slice(1))
.enter().append("circle")
.attr("r", function(d) { return d.r; })
.attr("cx", function(d) { return d.x; })
.attr("cy", function(d) { return d.y; })
.classed("group", function(d) { return d.children; })
.classed("planet", function(d) { return !d.children; })
.filter(function(d) { return d.data; })
.style("fill", function(d) {
return d.data.name ? color(d.data.population/1000) : 'white';
})
.style("stroke", function(d) {
if( d.children )
return 'black';
if( d.data.name === "Tatooine" )
return 'yellowgreen';
})
.style("stroke-width", '5px')
.on('mouseover', function(d) {
d3.selectAll('.planet').style('stroke', null)
if( d.children ) return;
d3.select(this).style('stroke', 'yellowgreen');
updateInfo(d);
})
.on('mouseout', function(d) {
if( d.children ) return;
d3.select(this).style('stroke', null);
});
data.filter( function(d) { return d.name === "Tatooine"; } ).map(updateInfo)
});
function type(d) {
d.size = +d.size;
d.known = +d.known;
d.distance = d.distance ? +d.distance : NaN;
return d;
}
function updateInfo(d) {
if(!d.data) d.data = d;
d3.select('#info').html( "<h1>" + d.data.name + "</h1>"
+ "<br>planet diameter: " + d.data.size + " KM"
+ "<br>planet population: " + (d.data.population ? d.data.population : "unknown")
+ "<br>planet orbital period: " + d.data.orbital_period + " days"
+ "<br>planet rotation period: " + d.data.rotation_period + " hours"
+ "<br>planet climate: " + d.data.climate
+ "<br>planet terrain: " + d.data.terrain
);
}
</script>
</body>