forked from OpenExoplanetCatalogue/oec_web
-
Notifications
You must be signed in to change notification settings - Fork 0
/
histogram.html
423 lines (381 loc) · 12.8 KB
/
histogram.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
<?include(".inc/prepend.php");?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<!-- If this is run as a php script on a server, you can include your own header that includes a navigation bar, and other stylistic features -->
<script language="php"> include "./.inc/header.php"; if (false){ </script>
<!-- ** start server side header ** -->
<head profile="http://www.w3.org/2005/10/profile">
<link rel="icon" type="image/ico" href="favicon.ico" />
<meta http-equiv="content-type" content="text/html; charset=UTF-8"/><meta name="description" content="description"/>
<title>Open Exoplanet Catalogue</title>
<link rel="stylesheet" type="text/css" href="./css/style.css" media="screen" />
<link rel="stylesheet" type="text/css" href="./css/tables.css" media="screen" />
<script type="text/javascript" src="./js/d3.v3.min.js"></script>
<script type="text/javascript" src="./js/rgbcolor.js"></script>
<script type="text/javascript" src="./js/canvg.js"></script>
<script type="text/javascript" src="./js/jquery.min.js"></script>
</head>
<body>
<div class="outer-container">
<div class="inner-container">
<div class="content">
<!-- ** end server side header ** -->
<script language="php"> } </script>
<!-- ########################### -->
<h2><img src="./img/kig.png" alt="kig" />Histograms</h2>
<p>This page is currently under development.
It uses the d3 javascript library to render histograms directly in your browser.
</p>
<!-- ########################### -->
<style>
label input {
margin-right:0.5em;
}
</style>
<table cellspacing="0" summary="Settings">
<tr>
<th scope="column" class="nobg"> </th>
<th scope="column" class="thname">Options</th>
</tr>
<tr>
<th rowspan=5 scope="row" class="spec">
<label>x-Axis</label>
</th>
<td class="data">
<select name="xaxis" onChange="updatePlot()">
<option value="semimajoraxis">Semi-major axis [AU]</option>
<option value="mass">Mass [MJup]</option>
<option selected value="radius">Radius [RJup]</option>
<option value="period">Period [days]</option>
<option value="eccentricity">Eccentricity</option>
<option value="temperature">Temperature [K]</option>
<option value="inclination">Inclination [deg]</option>
</select>
</td>
</tr>
<tr>
<td class="data">
<label for="logscalex"><input name="logscale" type="checkbox" value="x" id="logscalex" onClick="updatePlot()"/>Logarithmic scale</label>
</td>
</tr>
<tr>
<td class="data">
<label for="xrangeauto"><input checked name="xrangeauto" type="checkbox" value="a" id="xrangeauto" onClick="xrangeUpdate()"/>Automatic range</label>
</td>
</tr>
<tr>
<td class="data">
range = [<input type="text" name="xrangel" size=8 value="0" disabled onKeyUp="xrangeUpdate()"/>,
<input type="text" name="xranger" size=8 value="0" disabled onKeyUp="xrangeUpdate()"/>]
</td>
</tr>
<tr>
<td class="data">
<label for="xnumbins">Number of bins: <input type="text" name="xnumbins" size=3 value="20" onKeyUp="xrangeUpdate()"/></label>
</td>
</tr>
<tr>
<th rowspan=1 scope="row" class="spec">
<label>y-Axis</label>
</th>
<td class="data">
<label for="logscaley"><input name="logscale" type="checkbox" value="y" id="logscaley" onClick="updatePlot()"/>Logarithmic scale</label>
</td>
</tr>
<tr>
<th rowspan=6 class="spec" scope="row">
Filter (inclusive)
</th>
<td class="data">
<label for="filter_transit"><input checked name="discoveryfilter" type="checkbox" value="transit" id="filter_transit" onClick="updatePlot()"/>Transiting planets</label>
</td>
</tr>
<tr>
<td class="data">
<label for="filter_rv"><input checked name="discoveryfilter" type="checkbox" value="RV" id="filter_rv" onClick="updatePlot()"/>Radial velocity planets</label>
</td>
</tr>
<tr>
<td class="data">
<label for="filter_microlensing"><input checked name="discoveryfilter" type="checkbox" value="microlensing" id="filter_microlensing" onClick="updatePlot()"/>Microlensing planets</label>
</td>
</tr>
<tr>
<td class="data">
<label for="filter_imaged"><input checked name="discoveryfilter" type="checkbox" value="imaging" id="filter_imaged" onClick="updatePlot()"/>Directly imaged planets</label>
</td>
</tr>
<tr>
<td class="data">
<label for="filter_timing"><input checked name="discoveryfilter" type="checkbox" value="timing" id="filter_timing" onClick="updatePlot()"/>Planets found by pulsar timing</label>
</td>
</tr>
<tr>
<td class="data">
<label for="filter_other"><input checked name="discoveryfilter" type="checkbox" value="" id="filter_other" onClick="updatePlot()"/>Planets found by other methods</label>
</td>
</tr>
<tr>
<th rowspan="1" scope="row">
Export
</th>
<td>
<input type="button" onclick="saveaspng()" value="Save plot as png file" />
</td>
</tr>
</table>
<p>The plot updates automatically when the above parameters are changed</p>
<!-- ########################### -->
<script src="http://d3js.org/d3.v3.min.js"></script>
<div id="viz"></div>
<style>
#viz, .infobox {
font-family: sans-serif;
}
#viz text {
font-family: sans-serif;
font-size: 12px;
}
.axis path, .axis line {
shape-rendering: crispEdges;
}
</style>
<script type="text/javascript">
// Function to save the svg data (vector graphic) as a png file (bitmap).
// It draws the content to an HTML5 canvas and then redirects the bowser to a data url.
function saveaspng(){
d3.select("body").append("canvas")
.attr("width",width)
.attr("height",height)
.attr("id","canvas")
.style("display","none")
;
canvg('canvas', $("#viz").html());
window.location = document.getElementById("canvas").toDataURL("image/png");
}
var width = 600;
var height = 400;
var paddingt = 10;
var paddingb = 45;
var paddingl = 65;
var paddingr = 10;
var first = true;
var planetsxml = null;
var formatCount = d3.format(",.0f");
var viz = d3.select("#viz")
.append("svg")
.attr("width", width)
.attr("height", height)
;
var gxaxis = viz.append("g")
.attr("class", "axis")
.attr("transform", "translate(0," + (height - paddingb-paddingt) + ")");
;
var gyaxis = viz.append("g")
.attr("class", "axis")
.attr("transform", "translate(" + paddingl + ", 0)")
;
var gxaxislabel = viz.append("text")
.attr("text-anchor", "middle")
.attr("x", width/2.)
.attr("y", height - 6)
;
var gyaxislabel = viz.append("text")
.attr("text-anchor", "middle")
.attr("x", -height/2.)
.attr("y", 12)
.attr("transform", "rotate(-90)")
;
var xnumbins=20;
var xDomain;
var yDomain;
function xrangeUpdate(){
var needUpdate = false;
if(d3.select("#xrangeauto").node().checked){
d3.select("[name=xrangel]").attr("disabled",true);
d3.select("[name=xranger]").attr("disabled",true);
needUpdate = true;
}else{
d3.select("[name=xrangel]").attr("disabled",null);
d3.select("[name=xranger]").attr("disabled",null);
var newxDomain = [ parseFloat(d3.select("[name=xrangel]").node().value), parseFloat(d3.select("[name=xranger]").node().value) ];
if (newxDomain[0]!=xDomain[0] || newxDomain[1]!=xDomain[1]){
xDomain = newxDomain;
needUpdate = true;
}
}
var newxnumbins = Math.max(1,parseInt(d3.select("[name=xnumbins]").node().value));
if (newxnumbins!=xnumbins){
xnumbins = newxnumbins;
needUpdate = true;
}
if (needUpdate){
updatePlot();
}
}
function log10(val) {
return Math.log(val) / Math.LN10;
}
var updatePlot = function(){
var discoveryfilter = d3.selectAll("input[name=discoveryfilter]:checked");
var xkey = d3.select("select[name=xaxis]").node().options[d3.select("select[name=xaxis]").node().selectedIndex].value;
var logscalex = d3.select("#logscalex").node().checked;
var logscaley = d3.select("#logscaley").node().checked;
var planets = planetsxml.filter(function(d,i) {
//if (i>10) return false;
var discoverymethod = d3.select(d).select("discoverymethod");
if (discoverymethod.empty()){
discoverymethod = "";
}else{
discoverymethod = discoverymethod.text();
}
var isInSelection = false;
discoveryfilter[0].forEach(function(d){
if(d.value==discoverymethod){
isInSelection = true;
}
});
if (!isInSelection){
return false;
}
if(d3.select(d).select(xkey).empty()) return false;
if(logscalex && d3.select(d).select(xkey).text()<=0.) return false;
return true;
});
if(d3.select("#xrangeauto").node().checked){
xDomain = [
d3.min(planets, function(d) {
return parseFloat(d3.select(d).select(xkey).text());
}),
d3.max(planets, function(d) {
return parseFloat(d3.select(d).select(xkey).text());
})
];
if (logscalex){
xDomain[0] = log10(xDomain[0]);
xDomain[1] = log10(xDomain[1]);
}
d3.select("[name=xrangel]").node().value = xDomain[0];
d3.select("[name=xranger]").node().value = xDomain[1];
}
var xScale;
xScale = d3.scale.linear();
xScale.domain(xDomain).range([paddingl, width-paddingl-paddingr]);
var data = d3.layout.histogram()
.bins(xScale.ticks(xnumbins))
.range(xDomain)
.value(function(d){
if (logscalex){
return log10(d3.select(d).select(xkey).text());
}else{
return d3.select(d).select(xkey).text();
}
})
(planets);
if (logscaley){
yDomain = [0.5, d3.max(data, function(d) { return d.y; })]
}else{
yDomain = [0, d3.max(data, function(d) { return d.y; })]
}
var yScale;
if (logscaley){
yScale = d3.scale.log();
}else{
yScale = d3.scale.linear();
}
yScale.domain(yDomain).range([height - paddingb-paddingt,paddingt]);
var bar = viz.selectAll("rect")
.data(data);
bar.enter().append("rect")
.attr("class", "bar")
.style("fill", "steelblue")
.style("stroke", "black")
.attr("transform", function(d) {
return "translate(" + (xScale(d.x)+1) + "," + yScale(d.y) + ")";
})
.attr("width", function(d) {
return xScale(d.x+d.dx)-xScale(d.x);
})
.attr("height", function(d) {
if (logscaley){
return yScale(yDomain[0]) - yScale(Math.max(yDomain[0],d.y));
}else{
return yScale(yDomain[0]) - yScale(d.y);
}
});
bar = viz.selectAll("rect")
.data(data);
bar
.transition()
.attr("transform", function(d) {
return "translate(" + (xScale(d.x)+1) + "," + yScale(d.y) + ")";
})
.attr("width", function(d) {
return xScale(d.x+d.dx)-xScale(d.x);
})
.attr("height", function(d) {
if (logscaley){
return yScale(yDomain[0]) - yScale(Math.max(yDomain[0],d.y));
}else{
return yScale(yDomain[0]) - yScale(d.y);
}
})
;
bar.exit()
.remove();
var xlabel = d3.select("select[name=xaxis]").node().options[d3.select("select[name=xaxis]").node().selectedIndex].text;
var ylabel = "Number of planets";
var xAxis = d3.svg.axis()
.scale(xScale)
.ticks(5)
.orient("bottom");
var yAxis = d3.svg.axis()
.scale(yScale)
.ticks(5)
.orient("left");
if (first){
gxaxis.call(xAxis);
gyaxis.call(yAxis);
}else{
gxaxis.transition().call(xAxis);
gyaxis.transition().call(yAxis);
}
if (logscalex){
gxaxislabel.text("log10( " +xlabel+ " )");
}else{
gxaxislabel.text(xlabel);
}
gyaxislabel.text(ylabel);
gxaxis.selectAll("path,line")
.style("fill","none")
.style("stroke","black");
gyaxis.selectAll("path,line")
.style("fill","none")
.style("stroke","black");
first = false;
};
d3.xml("systems.xml", "application/xml", function(xml) {
planetsxml = d3.select(xml).selectAll("planet")[0];
updatePlot();
});
</script>
<div class="spacer" style="clear:left"></div>
<!-- ########################### -->
<h2><img src="./img/xml.png" alt="star" />Data download</h2>
<p>
The data presented in this plot is taken from the <a href="https://github.com/hannorein/open_exoplanet_catalogue">Open Exoplanet Catalogue</a>. All information on this page is directly generated from the XML files in the catalogue. If you are interested in how, look at the source code. You can download the entire catalogue on <a href="https://github.com/hannorein/open_exoplanet_catalogue/">github</a>. You can also find ASCII tables of the same catalogue <a href="https://github.com/hannorein/oec_tables/">in a separate repository</a>. Some information, especially in the case of a binary system cannot be easily represented in an ASCII table. You are therefore encouraged to use the original XML files provided by the Open Exoplanet Catalogue.
</p>
<!-- If run on a server, you can include your own footer -->
<script language="php"> include "./.inc/footer.php"; if (false){ </script>
<!-- ** start server side header ** -->
</div> <!-- content -->
<div class="clearer"> </div>
<div class="footer">
The data on this page is taken from the <a href="http://github.com/hannorein/open_exoplanet_catalogue">Open Exoplanet Catalogue</a>. The Open Exoplanet Catalogue as well as this website itself are licensed under an <a href="https://github.com/hannorein/open_exoplanet_catalogue/blob/master/README.md">MIT license</a>.
</div> <!-- footer -->
</div> <!-- inner container -->
</div> <!-- outer container -->
</body>
</html>
<!-- ** end server side header ** -->
<script language="php"> } </script>