-
Notifications
You must be signed in to change notification settings - Fork 2
/
ephemeris.js
86 lines (75 loc) · 3.54 KB
/
ephemeris.js
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
"use strict";
// Retrieves the transition duration of an element, in milliseconds
function transition_duration(element_id) {
var element = document.getElementById(element_id);
var element_style = window.getComputedStyle(element);
// Here's hoping that this value's name is consistent across browsers
var duration_string = element_style.getPropertyValue('transition-duration');
// A duration string is of the form "0.5s"
// Here's hoping that form is consistent across browsers
var duration_ms = 1000 * parseFloat(duration_string.replace(/s$/, ''));
return duration_ms;
}
// Configuration options for the progress spinner
var opts = {
lines: 13, // The number of lines to draw
length: 0, // The length of each line
width: 3, // The line thickness
radius: 60, // The radius of the inner circle
corners: 1, // Corner roundness (0..1)
rotate: 0, // The rotation offset
direction: 1, // 1: clockwise, -1: counterclockwise
color: '#fff', // #rgb or #rrggbb or array of colors
speed: 1, // Rounds per second
trail: 60, // Afterglow percentage
shadow: false, // Whether to render a shadow
hwaccel: true, // Whether to use hardware acceleration
className: 'spinner', // The CSS class to assign to the spinner
zIndex: 2e9, // The z-index (defaults to 2000000000)
top: '200px', // Top position relative to parent in px
left: 'auto' // Left position relative to parent in px
};
var spinner = new Spinner(opts);
// Get the current day, then set the time to sometime tonight
var tonight_local_time = moment().hour(22).minute(0).second(0);
var tonight_utc = tonight_local_time.clone().utc();
var info = tonight_local_time.format('dddd, MMM D, hh:mm A') +
' local time (UTC' + tonight_local_time.format('Z') + ')';
var ajax = new XMLHttpRequest();
ajax.onreadystatechange = function() {
if (ajax.readyState == 4 && ajax.status == 200) {
var positions = JSON.parse(ajax.responseText);
var table_html = '<table>';
for (var i=0; i<positions.today.length; i++) {
var planet = positions.today[i];
table_html += '<tr' + (planet.has_changed_since_yesterday ? ' class="changed"' : '') + '>' +
'<td>' + planet.name + '</td>' +
'<td>' + planet.degrees + '</td>' +
'<td class="sign">' + planet.sign + '</td>' +
'<td>' + (planet.is_retrograde ? 'Rx' : '') + '</td>' +
'</tr>';
}
table_html += '</table>';
document.getElementById('positions').innerHTML = table_html;
document.getElementById('info').innerHTML = info;
var spinner_fadeout_duration = transition_duration('spinner');
var content_fadein_duration = transition_duration('content');
// Trigger the CSS transition to hide the spinner...
document.getElementById('spinner').className = 'hidden';
// ...then stop the spinner once it's done
setTimeout(function() {
spinner.stop();
// Trigger the CSS transition to show the data...
document.getElementById('content').className = '';
// ...then start drawing the galaxy once it's done
setTimeout(function() {
milky.draw_galaxy();
}, content_fadein_duration);
}, spinner_fadeout_duration);
}
};
window.onload = function() {
spinner.spin(document.getElementById('spinner'));
ajax.open('GET', 'ajax/positions?date=' + tonight_utc.toISOString(), true);
ajax.send();
};