-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.html
200 lines (170 loc) · 5 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
<!DOCTYPE HTML>
<html lang="en">
<head>
<title>Internet Users by Country (WebGL Globe)</title>
<meta charset="utf-8">
<style type="text/css">
html {
height: 100%;
}
body {
margin: 0;
padding: 0;
background: #000000 url(/img/loading.gif) center center no-repeat;
color: #ffffff;
font-family: sans-serif;
font-size: 13px;
line-height: 20px;
height: 100%;
}
#info {
font-size: 11px;
position: absolute;
bottom: 5px;
background-color: rgba(0,0,0,0.8);
border-radius: 3px;
right: 10px;
padding: 10px;
}
#currentInfo {
font: Verdana;
width: 270px;
position: absolute;
left: 20px;
top: 63px;
background-color: rgba(0,0,0,0.2);
border-top: 1px solid rgba(255,255,255,0.4);
padding: 10px;
}
a {
color: #aaa;
text-decoration: none;
}
a:hover {
text-decoration: underline;
}
.bull {
padding: 0 5px;
color: #555;
}
#title {
position: absolute;
top: 20px;
width: 340px;
left: 20px;
background-color: rgba(0,0,0,0.2);
border-radius: 3px;
font: 20px Verdana;
padding: 10px;
}
.year {
visibility: hidden;
width: 300px;
}
</style>
</head>
<body>
<div id="container"></div>
<div id="info">
<strong>Created by <a href="http://matthewmuccio.com" target="_blank">Matthew Muccio</a> <span class="bull">•</span>
Source code on <a href="https://github.com/matthewmuccio/WebGLGlobe" target="_blank">GitHub</a>
<span class="bull">•</span>
Powered by <a href="http://www.chromeexperiments.com/globe" target="_blank">WebGL Globe</a>
<span class="bull">•</span>
Data from <a href="http://www.internetlivestats.com/internet-users-by-country" target="_blank">Internet Live Stats</a>
<span class="bull">•</span>
Coordinates from <a href="https://developers.google.com/public-data/docs/canonical/countries_csv" target="_blank">Google Developers</a>
<span class="bull">•</span>
WebGL Globe by the Google Data Arts Team</strong>
</div>
<div id="currentInfo">
<span id="year2016" class="year">2016</span>
</div>
<div id="title">
Internet Users by Country (2016)
</div>
<script type="text/javascript" src="/lib/Detector.js"></script>
<script type="text/javascript" src="/lib/three.min.js"></script>
<script type="text/javascript" src="/lib/Tween.js"></script>
<script type="text/javascript" src="/globe.js"></script>
<script type="text/javascript">
// If WebGL is not detected on the browser.
if(!Detector.webgl)
{
Detector.addGetWebGLMessage();
}
else
{
// Array which stores the available years.
var years = ['2016'];
// Where to put the WebGL globe.
var container = document.getElementById('container');
// Make the globe; store it in a variable.
var globe = new DAT.Globe(container);
console.log(globe);
var i, tweens = [];
// What happens when the user selects a new time.
var settime = function(globe, t)
{
return function()
{
new TWEEN.Tween(globe).to({time: t}, 500).easing(TWEEN.Easing.Cubic.EaseOut).start();
var y = document.getElementById('year' + years[t]);
if (y.getAttribute('class') === 'year active')
{
return;
}
var yy = document.getElementsByClassName('year');
for (i = 0; i < yy.length; i++)
{
yy[i].setAttribute('class','year');
}
y.setAttribute('class', 'year active');
};
};
for(var i = 0; i < years.length; i++)
{
var y = document.getElementById('year' + years[i]);
y.addEventListener('mouseover', settime(globe,i), false);
}
// Stores XML HTTP Request object in order obtain JSON data.
var xhr;
TWEEN.start();
// Asking a file for the JSON data.
xhr = new XMLHttpRequest();
// Opening the file which holds the JSON data.
xhr.open('GET', '/data.json', true);
// What happens when we receive the data.
xhr.onreadystatechange = function(e)
{
// If data is received.
if (xhr.readyState === 4)
{
if (xhr.status === 200)
{
// Parse the JSON data.
var data = JSON.parse(xhr.responseText);
// Set data in the current window to the parsed JSON data.
window.data = data;
// Tell the WebGL globe about your JSON data.
for (i = 0; i < data.length; i++)
{
globe.addData(data[i][1], {format: 'magnitude', name: data[i][0], animated: true});
}
// Create the geometry.
globe.createPoints();
// Use settime function to set time to 0 (2016).
settime(globe, 0)();
// Begin animation.
globe.animate();
// Remove loading GIF.
document.body.style.backgroundImage = 'none';
}
}
};
// Begin request.
xhr.send(null);
}
</script>
</body>
</html>