-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathindex.html
193 lines (161 loc) · 6.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
<!DOCTYPE html>
<html>
<head>
<title>sunny</title>
<meta name="author" content="unividuell">
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<!--Load the AJAX API-->
<script type="text/javascript" src="https://www.google.com/jsapi"></script>
<!-- Load the suncalc lib-->
<script type="text/javascript" src="js/suncalc.js"></script>
<!-- Load the Google maps API v3 -->
<script type="text/javascript"
src="https://maps.googleapis.com/maps/api/js?key=AIzaSyCB8VM7adC1V60gv78IiZ8NrW3RVR2J3hI&sensor=true"></script>
<!-- my CSS -->
<style type="text/css">
html { height: 99%; font-family: monospace; }
body { height: 98%; margin: 0; padding: 0 }
#map_canvas { height: 100% }
.mark {background-color: #CC6F05; color: #c0ffee; text-decoration: none; padding: 0 4px;}
</style>
<script type="text/javascript">
/* ################################################################## *
* global stuff
* ################################################################## */
// ulm
var lat = 48.398530;
var lng = 9.991205;
// year
var year = new Date().getFullYear();
// the map
var map;
var marker;
var geocoder;
// color
var night = '#282729';
var sunshine = '#CC6F05';
var nowColor = "#0591CC";
/* ################################################################## *
* chart stuff
* ################################################################## */
// Load the Visualization API and the piechart package.
google.load('visualization', '1.1', {'packages':['corechart']});
// Set a callback to run when the Google Visualization API is loaded.
// gmaps forces an update: is this a good idea?
// google.setOnLoadCallback(drawChart);
function diff(diff) {
// millisec / sec / minute
// * 100 / 100 -> x,yy
return Math.round((diff/1000/60/60) * 100) / 100;
}
function drawChart() {
// Create and populate the data table.
var data = new google.visualization.DataTable();
// date
var myDate = new Date(year, 0, 1, 12);
var now = new Date();
// Add columns
data.addColumn('date', 'Day'); var indexHead = 0;
// ordering this way because of areaOpacity.
data.addColumn('timeofday', 'midnight'); var indexMidnight = 1;
data.addColumn('timeofday', 'sunset'); var indexSunset = 2;
data.addColumn('timeofday', 'sunrise'); var indexSunrise = 3;
data.addColumn('timeofday', 'now'); var indexNow = 4;
var maxThisYear = new Date(year+1, 0, 1);
for (var cnt = 0; myDate.getTime() <= maxThisYear.getTime(); cnt = cnt+1) {
var crtDate = new Date(myDate);
// get today's sunlight times
var times = SunCalc.getTimes(crtDate, lat, lng);
// data - raw
data.addRow();
data.setCell(cnt, indexHead, crtDate);
data.setCell(cnt, indexSunrise, [times.sunrise.getHours(), times.sunrise.getMinutes(), times.sunrise.getSeconds()]);
data.setCell(cnt, indexSunset, [times.sunset.getHours(), times.sunset.getMinutes(), times.sunset.getSeconds()]);
data.setCell(cnt, indexMidnight, [23, 59, 59]);
// now
if (crtDate.getYear() == now.getYear()
&& crtDate.getMonth() == now.getMonth()
&& crtDate.getDate() == now.getDate()) {
data.setCell(cnt, indexNow, [now.getHours(), now.getMinutes(), now.getSeconds()]);
}
myDate.setDate(myDate.getDate()+1);
}
var options = {
title:'Sunny',
width:'100%',
height:320,
vAxis: {ticks: [[0, 0, 0], [6, 0, 0], [8, 0, 0], [10, 0, 0], [16, 0, 0], [18, 0, 0], [20, 0, 0], [23, 59, 59]]},
hAxis: {ticks: [new Date(year, 0, 1)]},
chartArea: {left: 50, top: 15, width: '95%', height: '80%'},
legend: { position: "none" },
// fontName: 'monospace',
titlePosition: 'none',
series: {
0:{color: night, areaOpacity: 1}, // after sunset
1:{color: sunshine, areaOpacity: 1}, // sunshine
2:{color: night, areaOpacity: 1}, // before sunrise
3:{color: nowColor, areaOpacity: 0, lineWidth: 0, pointSize: 4} // now
},
selectionMode: 'multiple',
};
// Create and draw the visualization.
var chart = new google.visualization.AreaChart(document.getElementById('chart_div'));
chart.draw(data, options);
}
/* ################################################################## *
* map stuff
* ################################################################## */
function initMap() {
geocoder = new google.maps.Geocoder();
var mapOptions = {
center: new google.maps.LatLng(lat, lng),
zoom: 1,
mapTypeId: google.maps.MapTypeId.ROADMAP
};
map = new google.maps.Map(
document.getElementById("map_canvas"),
mapOptions);
marker = new google.maps.Marker({
position: map.getCenter(),
map: map,
title: 'LOCATION'
});
placeMarker(map.getCenter());
google.maps.event.addListener(map, 'click', function(event) {
placeMarker(event.latLng);
});
document.getElementById('yearInTitle').innerHTML = year;
}
function placeMarker(location) {
marker.setPosition(location);
lat = location.lat();
lng = location.lng();
// chart update
drawChart();
codeLatLng(location);
}
function codeLatLng(location) {
geocoder.geocode(
{'latLng': location},
function(results, status) {
if (status == google.maps.GeocoderStatus.OK) {
if (results[1]) {
document.getElementById("location").innerHTML = results[1].formatted_address + " " + location.toString();
}
} else {
alert("Geocoder failed due to: " + status);
}
});
}
</script>
</head>
<body onload="initMap()">
<h3><span class="mark">☀☀☀☀☀</span>: <span class="mark">sunrise / sunset</span> during <span id="yearInTitle" class="mark">2014</span></span> @<span id="location" class="mark">kn</span></h3>
<div>
<div id="chart_div"></div>
<div id="map_canvas" style="width:100%; height:250px"></div>
</div>
<p style="text-align: right;">this is a <b>quick & dirty</b> production of <a class="mark" href="http://unividuell.org">unividuell</a>;
credits to <a style="color: #CC6F05; text-decoration: none;" href="https://github.com/mourner/suncalc">suncalc</a>!</p>
</body>
</html>