-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
203 lines (180 loc) · 4.56 KB
/
index.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
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
let Globe_Spark;
let Globe_Normal;
let Amount_Spark = 0;
let Amount_Normal = 1;
let Stack_Spark = 0;
let Stack_Normal = 0;
let Stack_Max = 100;
let Stack_Height = document.querySelector("#spark > footer").offsetHeight;
function Init_Globe_Spark() {
let planetaryjs = window.planetaryjs;
let canvas = document.getElementById("globe_spark");
let r = parseInt(canvas.getAttribute("height")) / 2;
Globe_Spark = planetaryjs.planet();
Globe_Spark.loadPlugin(
planetaryjs.plugins.earth({
topojson: {
file: "lib/planetary.js/dist/world-110m.json",
},
oceans: {
fill: "#36F",
},
land: {
fill: "#FFF",
},
borders: {
stroke: "#36F",
},
})
);
Globe_Spark.loadPlugin(Middleware_Autorotate(30));
Globe_Spark.loadPlugin(planetaryjs.plugins.pings());
Globe_Spark.loadPlugin(
planetaryjs.plugins.drag({
onDragStart: function () {
this.plugins.autorotate.pause();
},
onDragEnd: function () {
this.plugins.autorotate.resume();
},
})
);
Globe_Spark.projection.scale(r).translate([r, r]);
Globe_Spark.draw(canvas);
}
function Init_Globe_Normal() {
let planetaryjs = window.planetaryjs;
let canvas = document.getElementById("globe_normal");
let r = parseInt(canvas.getAttribute("height")) / 2;
Globe_Normal = planetaryjs.planet();
Globe_Normal.loadPlugin(
planetaryjs.plugins.earth({
topojson: {
file: "lib/planetary.js/dist/world-110m.json",
},
oceans: {
fill: "#222",
},
land: {
fill: "#666",
},
borders: {
stroke: "#222",
},
})
);
Globe_Normal.loadPlugin(Middleware_Autorotate(10));
Globe_Normal.loadPlugin(planetaryjs.plugins.pings());
Globe_Normal.loadPlugin(
planetaryjs.plugins.drag({
onDragStart: function () {
this.plugins.autorotate.pause();
},
onDragEnd: function () {
this.plugins.autorotate.resume();
},
})
);
Globe_Normal.projection.scale(r).translate([r, r]);
Globe_Normal.draw(canvas);
}
function Middleware_Autorotate(degPerSec) {
return function (planet) {
let lastTick = null;
let paused = false;
planet.plugins.autorotate = {
pause: function () {
paused = true;
},
resume: function () {
paused = false;
},
};
planet.onDraw(function () {
if (paused || !lastTick) {
lastTick = new Date();
} else {
let now = new Date();
let delta = now.getTime() - lastTick.getTime();
let rotation = planet.projection.rotate();
rotation[0] += (degPerSec * delta) / 1000;
if (rotation[0] >= 180) rotation[0] -= 360;
planet.projection.rotate(rotation);
lastTick = now;
}
});
};
}
function Dummy_Data_Pump() {
// Pump Spark data
setInterval(function () {
let range = Math.random() * 10 + 5;
for (let i = 0; i < range; i++) {
let data = {
longitute: Math.random() * 170 - 85,
latitude: Math.random() * 360 - 180,
};
let color = "red";
Globe_Spark.plugins.pings.add(data.longitute, data.latitude, {
color: color,
ttl: 500,
angle: 10,
});
Amount_Spark++;
Stack_Spark++;
}
}, 100);
// Pump Normal data
setInterval(function () {
let data = {
longitute: Math.random() * 170 - 85,
latitude: Math.random() * 360 - 180,
};
let color = "red";
Globe_Normal.plugins.pings.add(data.longitute, data.latitude, {
color: color,
ttl: 5000,
angle: 10,
});
Amount_Normal++;
Stack_Normal++;
}, 200);
// Render Amount
setInterval(function () {
document.querySelector("#spark > .amount").innerHTML = Amount_Spark;
document.querySelector("#normal > .amount").innerHTML = Amount_Normal;
document.querySelector("body > footer > div").innerHTML = (
Amount_Spark / Amount_Normal
).toFixed(0);
}, 10);
// Render Stack
setInterval(function () {
let TD_Spark = document.createElement("td");
let DIV_Spark = document.createElement("div");
TD_Spark.appendChild(DIV_Spark);
document
.querySelector("#spark > footer > table > tbody > tr")
.appendChild(TD_Spark);
DIV_Spark.offsetWidth = DIV_Spark.offsetWidth;
DIV_Spark.style.height =
(Stack_Spark / Stack_Max) * Stack_Height + "px";
Stack_Spark = 0;
let TD_Normal = document.createElement("td");
let DIV_Normal = document.createElement("div");
TD_Normal.appendChild(DIV_Normal);
document
.querySelector("#normal > footer > table > tbody > tr")
.insertBefore(
TD_Normal,
document.querySelector("#normal > footer > table > tbody > tr")
.firstChild
);
DIV_Normal.offsetWidth = DIV_Normal.offsetWidth;
DIV_Normal.style.height =
(Stack_Normal / Stack_Max) * Stack_Height + "px";
Stack_Normal = 0;
}, 500);
}
Init_Globe_Spark();
Init_Globe_Normal();
Dummy_Data_Pump();