-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.html
516 lines (430 loc) · 22.4 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
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
<!-- CS50 Final Project
Fall 2013
Erin Braswell
index.html
-->
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="content-type" content="text/html; charset=UTF8">
<title>ErinSpace</title>
<link rel="stylesheet" type="text/css" href="./css/style.css"/>
<link rel="stylesheet" type="text/css" href="./css/bootstrap.css"/>
<link rel="stylesheet" type="text/css" href="./css/bootstrap-responsive.css"/>
<script type = "text/javascript" src="./js/d3.v3.js"></script>
<script type="text/javascript" src="./js/jquery-1.10.2.js"></script>
<script type="text/javascript" src="./js/bootstrap.js"></script>
<!-- show the plot on load -->
<script type="text/javascript">
$( document ).ready(function() {
updatePlot();
});
</script>
<!-- Google analytics, cause why not -->
<script>
(function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){
(i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),
m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m)
})(window,document,'script','//www.google-analytics.com/analytics.js','ga');
ga('create', 'UA-15229886-1', 'erinspace.net');
ga('send', 'pageview');
</script>
</head>
<body>
<script>
// load the XML and set up the data object
var source = "systems.xml";
var data = [];
// extracting objects from the XML
d3.xml(source, "text/xml", function(xml) {
d3.select(xml).selectAll("planet").each(
function() {
var planet = {};
var name = d3.select(this).select("name");
var mass = d3.select(this).select("mass");
var radius = d3.select(this).select("radius");
var period = d3.select(this).select("period");
var semimajoraxis = d3.select(this).select("semimajoraxis");
var discoverymethod = d3.select(this).select("discoverymethod");
var discoveryyear = d3.select(this).select("discoveryyear");
var description =d3.select(this).select("description");
// check to see if the planet has all the properties we want
// and add it to the data object if it does
if(name[0][0] && mass[0][0] && radius[0][0] && period[0][0] && semimajoraxis[0][0]) {
if(mass.text() != "") {
planet.name = name.text();
planet.mass = parseFloat(mass.text());
planet.radius = parseFloat(radius.text());
planet.period = parseFloat(period.text());
planet.semimajoraxis = parseFloat(semimajoraxis.text());
if(!discoverymethod[0][0]) {
planet.discoverymethod = "not recorded";
}
else {
planet.discoverymethod = discoverymethod.text();
}
// fudge the discovery years to make the graph better
if(!discoveryyear[0][0] || discoveryyear.text() < 1990) {
planet.discoveryyear = "2011";
}
else {
planet.discoveryyear = discoveryyear.text();
}
if(!description[0][0]) {
planet.description = "The database dosen't seem to have a description for this planet at the moment. Check back later!";
}
else {
planet.description = description.text();
}
data.push(planet);
}
}
}
)
});
//set the default parameters
var xkey = "radius";
var ykey = "mass";
var point_radius = "radius";
var point_color = "discoveryyear";
var xunit = "[R Jupiter]"
var yunit = "[M Jupiter]"
// set up the scatterplot variables
var margin = {top: 20, right: 75, bottom: 40, left: 80},
width = 800 - margin.left - margin.right,
height = 600 - margin.top - margin.bottom;
// set up information for the svg element
var x = d3.scale.linear()
.range([0, width]);
var y = d3.scale.linear()
.range([height, 0]);
var color = d3.scale.category10();
// functions for updating the scale
var updateScaleLinear_x = function() {
x = d3.scale.linear()
.range([0, width]);
updatePlot();
}
var updateScaleLog_x = function() {
x = d3.scale.log()
.range([0, width]);
updatePlot();
}
var updateScaleLinear_y = function() {
y = d3.scale.linear()
.range([height, 0]);
updatePlot();
}
var updateScaleLog_y = function() {
y = d3.scale.log()
.range([height, 0]);
updatePlot();
}
// for the "Research Questions" below, sets the graph to look a certain way
var customGraph = function (xparam, yparam, radius, xscale, yscale) {
xkey = xparam;
ykey = yparam;
point_radius = radius;
if(xscale == "log") {
updateScaleLog_x();
}
else {
updateScaleLinear_x();
}
if(yscale == "log") {
updateScaleLog_y();
}
else {
updateScaleLinear_y();
}
updatePlot();
}
// read the values from the axes select choices
var setAxes = function() {
xkey = $(xaxis).val();
ykey = $(yaxis).val();
point_color = $(pointcolor).val();
point_radius = $(pointradius).val();
}
// update the entire plot
var updatePlot = function() {
var x_axis = d3.svg.axis()
.scale(x)
.orient("bottom");
var y_axis = d3.svg.axis()
.scale(y)
.orient("left");
// add the planet info tooltip
var div = d3.select("#plot").append("div")
.attr("class", "tooltip")
.style("opacity", 0);
// set the units for the axes and check for years
if (xkey == "mass") {
xunit = "[M Jupiter]";
}
else if (xkey == "radius") {
xunit = "[R Jupiter]";
}
else if (xkey == "period") {
xunit = "[Days]";
}
else if (xkey == "discoveryyear") {
xunit = "[Earth Year]";
x_axis = x_axis.tickFormat(d3.format("0000"));
}
else if (xkey == "semimajoraxis") {
xunit = "[AU]";
}
if (ykey == "mass") {
yunit = "[M Jupiter]";
}
else if (ykey == "radius") {
yunit = "[R Jupiter]";
}
else if (ykey == "period") {
yunit = "[Days]";
}
else if (ykey == "discoveryyear") {
yunit = "[Earth Year]";
y_axis = y_axis.tickFormat(d3.format("0000"));
}
else if (ykey == "semimajoraxis") {
yunit = "[AU]";
}
// get rid of the old graph
d3.select("svg").remove();
// create a new svg element
var svg = d3.select("#plot")
.append("svg")
.attr("width", width + margin.left + margin.right)
.attr("height", height + margin.top + margin.bottom)
.append("g")
.attr("transform", "translate(" + margin.left + "," + margin.top + ")");
// set domains for both x and y
x.domain(d3.extent(data, function(d) { return d[xkey]; })).nice();
y.domain(d3.extent(data, function(d) { return d[ykey]; })).nice();
// adds different 'g' elements to the svg plot
// x axis
svg.append("g")
.attr("class", "x axis")
.attr("transform", "translate(0," + height + ")")
.call(x_axis)
.append("text")
.attr("class", "label")
.attr("x", width)
.attr("y", 35)
.style("text-anchor", "end")
.text(xkey + " " + xunit);
// y-axis
svg.append("g")
.attr("class", "y axis")
.call(y_axis)
.append("text")
.attr("class", "label")
.attr("transform", "rotate(-90)")
.attr("y", -80)
.attr("dy", ".71em")
.style("text-anchor", "end")
.text(ykey + " " + yunit);
// add the circles to the graph
svg.selectAll(".dot")
.data(data)
.enter().append("circle")
.attr("class", "dot")
.attr("r", function(d) {
if(point_radius == "constant") {
return 4;
}
return d[point_radius] * 4 ; })
.attr("cx", function(d) { return x(d[xkey]); })
.attr("cy", function(d) { return y(d[ykey]); })
.style("fill", function(d) { return color(d[point_color]); })
.style("stroke", "black")
.style("opacity", 0.7)
.on("mouseover", function(d) {
div.transition()
.duration(200)
.style("opacity", 0.7);
div .html("<b>" + d.name + "</b> <br/><div align=\"justify\">" +
d.description + "<br/><br/><small>Mass: " + d.mass + " [M Jupiter]<br/>Radius: " + d.radius +
" [R Jupiter]<br/> Semi-major Axis: " + d.semimajoraxis + " [AU]</small></div>")
})
.on("mouseout", function(d) {
div.transition()
.duration(500)
.style("opacity", 0);
});
// create a color legend
var legend = svg.selectAll(".legend")
.data(color.domain())
.enter().append("g")
.attr("class", "legend")
.attr("transform", function(d, i) { return "translate(0," + i * 20 + ")"; });
// add the legend colors to the svg object
legend.append("rect")
.attr("x", width + 18 )
.attr("width", 18)
.attr("height", 18)
.style("fill", color);
// add text to the legend
legend.append("text")
.attr("x", width + 75)
.attr("y", 9)
.attr("dy", ".35em")
.style("text-anchor", "end")
.text(function(d) { return d; });
};
</script>
<div class="container">
<div class="header">
<ul class="nav nav-pills pull-right">
<li class="active"><a href="#">Home</a></li>
<li><a href="documentation.html">Documentation</a></li>
<li><a href="design.html">Design</a></li>
</ul>
<h3 class="text-muted">ErinSpace</h3>
</div>
<div class="container-fluid">
<div class="row-fluid">
<div class="span3">
<img id="star" src="./img/sun.png">
<div id='planet1-orbit'>
<img id="planet1" src="./img/planet.png">
</div>
<br/>
<br/>
<br/>
<p class="heading">Exploring</p>
<h1 class="title">Exoplanets</h1>
<p>
Use these controls to explore exoplanet data from the <a href="http://www.openexoplanetcatalogue.com/">Open Exoplanet Catalog</a>.
</p>
<p>Choose an option from the drop-down menus below to get started.</p>
<p>Once you have a graph, hover over each point to see the planet's name and a description!</p>
<table>
<tr>
<td>x-axis</td>
<td>
<select id="xaxis" class="form-control" onchange="setAxes();updatePlot()">
<option value="radius">Radius</option>
<option value="mass">Mass</option>
<option value="period">Period</option>
<option value="semimajoraxis">Semimajor Axis</option>
<option value="discoveryyear">Discovery Year</option>
</select>
</td>
</tr>
<tr>
<td id="label">scale</td>
<td>
<label class="radio-inline">
<input type="radio" name="optionsRadios" id="optionsrRadios1" onClick="updateScaleLinear_x()" checked>
Linear
</label>
<label class="radio-inline">
<input type="radio" name="optionsRadios" id="optionsrRadios2" onClick="updateScaleLog_x()">
Log
</label>
</td>
</tr>
<tr><td> _ </td></tr>
<tr>
<td>y-axis</td>
<td>
<select id="yaxis" class="form-control" onchange="setAxes();updatePlot()">
<option value="mass">Mass</option>
<option value="radius">Radius</option>
<option value="period">Period</option>
<option value="semimajoraxis">Semimajor Axis</option>
<option value="discoveryyear">Discovery Year</option>
</select>
</td>
</tr>
<tr>
<td id="label">scale</td>
<td>
<label class="radio-inline">
<input type="radio" name="optionsRadios2" id="optionsrRadios3" onClick="updateScaleLinear_y()" checked>
Linear
</label>
<label class="radio-inline">
<input type="radio" name="optionsRadios2" id="optionsrRadios4" onClick="updateScaleLog_y()">
Log
</label>
</td>
</tr>
<tr><td> _ </td></tr>
<tr>
<br/>
<td>size</td>
<td>
<select id="pointradius" class="form-control" onchange="setAxes();updatePlot()">
<option value="radius">Radius</option>
<option value="mass">Mass</option>
<option value="constant">constant</option>
</select>
</td>
</tr>
<tr>
<td>color</td>
<td>
<select id="pointcolor" class="form-control" onchange="setAxes();updatePlot()">
<option value="discoveryyear">discovery year</option>
</select>
</td>
</tr>
</table>
</div>
<div class="span9">
<div id="plot"></div>
</div>
</div>
<div class="span8">
<h2>Guide</h2>
<p class="lead">There's a lot of terminology on this page - here are some quick explanations</p>
<table class="table">
<tr>
<td><a href="http://en.wikipedia.org/wiki/Exoplanet">Exoplanet</a></td><td>Short for "extra-solar planet"; a planet going around a star other than our Sun</td>
<tr>
<td>[M Jupiter]<br/>[R Jupiter]</td><td><br/>As a point of reference, Astronomers usually compare an exoplanet's mass and radius to <a href="http://en.wikipedia.org/wiki/Jupiter">Jupiter</a></td>
</tr>
<tr>
<td><a href="http://en.wikipedia.org/wiki/Orbital_period">Period</a></td><td>The amount of time (in Earth days) that the planet takes to go around its star</td>
</tr>
<tr>
<td><a href="http://en.wikipedia.org/wiki/Semi-major_axis">Semimajor axis</a></td><td>A measure of how far away the planet orbits from its star. </td>
</tr>
<tr>
<td><a href="http://en.wikipedia.org/wiki/Astronomical_unit">[AU]</a></td><td>1 AU is the distance the Earth is from the Sun - used as a point of reference when measuring a semimajor axis</td>
</tr>
</table>
<h2>Research Questions!</h2>
<p class="lead">With just a little exploration, you can answer all sorts of interesting questions</p>
<table class="table">
<tr>
<td>Which exoplanet in the dataset has the highest mass?</td>
<td><button type="button" class="btn btn-default" onclick="customGraph('mass', 'mass', 'constant', 'log', 'log')">check out the graph</button></td>
</tr>
<tr>
<td>What year did exoplanet discovery really take off? When do planets discovered using the <a href="http://kepler.nasa.gov/">Kepler space telescope </a>start showing up? How did the mass of planets that we were able to discover change over time?</td>
<td><button type="button" class="btn btn-default" onclick="customGraph('discoveryyear','mass','constant','linear','log')">plot it</button></td>
</tr>
<tr>
<td>What's the average semimajor axis for planets discovered? Are there any planets that are orbiting around their stars about the same distance as Earth? (1 AU or 1e+0 on the axes...).</td>
<td><button type="button" class="btn btn-default" onclick="customGraph('semimajoraxis','radius','constant','log','linear')">see for yourself</button></td>
</tr>
<tr>
<td>How has the average semimajor axis of discovered planets changed over time? What does that say about exoplanet finding techniques?</td>
<td><button type="button" class="btn btn-default" onclick="customGraph('semimajoraxis','discoveryyear','radius','log','linear')">check it out</button></td>
</tr>
</table>
</div>
</div>
</div>
<div id="footer">
<div class="container">
<p class="text-muted">CS50 Fall 2013 Final Project by Erin Braswell</p>
</div>
</div>
</body>
</html>