-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
322 lines (273 loc) · 11.3 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
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
const { ipcRenderer } = require('electron');
var wdata = {};
var calendar_month = 1;
var calendar_day = 1;
var month_days = [0, 31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31];
var month_names = ["", "January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December"];
window.onload = function () {
document.getElementById("closebtn").onclick = function () {
ipcRenderer.send('close');
}
init_map();
var btn_dashboard = document.getElementById("btn_dashboard");
var btn_map = document.getElementById("btn_map");
var btn_collections = document.getElementById("btn_collections");
var btn_about = document.getElementById("btn_about");
var dashboard = document.getElementById("dashboard");
var map = document.getElementById("mapcontainer");
var collections = document.getElementById("collections");
var about = document.getElementById("about");
btn_dashboard.onclick = function () {
dashboard.style.display = "block";
map.style.display = "none";
collections.style.display = "none";
about.style.display = "none";
btn_dashboard.className = "tab_on";
btn_about.className = "tab";
btn_collections.className = "tab";
btn_map.className = "tab";
}
btn_about.onclick = function () {
dashboard.style.display = "none";
map.style.display = "none";
collections.style.display = "none";
about.style.display = "block";
btn_dashboard.className = "tab";
btn_about.className = "tab_on";
btn_collections.className = "tab";
btn_map.className = "tab";
}
btn_map.onclick = function () {
dashboard.style.display = "none";
map.style.display = "block";
collections.style.display = "none";
about.style.display = "none";
btn_dashboard.className = "tab";
btn_about.className = "tab";
btn_collections.className = "tab";
btn_map.className = "tab_on";
}
btn_collections.onclick = function () {
dashboard.style.display = "none";
map.style.display = "none";
collections.style.display = "block";
about.style.display = "none";
btn_dashboard.className = "tab";
btn_about.className = "tab";
btn_collections.className = "tab_on";
btn_map.className = "tab";
}
document.getElementById('search_btn').onclick = function () {
btn_dashboard.onclick();
ipcRenderer.send('GetData', document.getElementById("search_text").value);
}
ipcRenderer.on('ShowDetail', function (event, data) {
document.getElementById("citylist").style.display = "none";
document.getElementById("dashboard_container").style.display = "flex";
console.log(data);
wdata = data;
console.log(wdata);
const parentDiv = document.getElementById("days");
const childElements = parentDiv.children;
for (const child of childElements) {
child.removeAttribute("class");
}
document.getElementById("months").value = "January";
childElements[0].setAttribute("class", "active");
LoadGraph(1);
ShowDetail(101);
calendar_month = 1;
calendar_day = 1;
update_calendar();
});
document.getElementById("pre_btn").onclick = function () {
calendar_day = 1;
if (calendar_month == 1) calendar_month = 12;
else calendar_month--;
document.getElementById("months").innerHTML = month_names[calendar_month];
update_calendar();
LoadGraph(calendar_month);
}
document.getElementById("next_btn").onclick = function () {
calendar_day = 1;
if (calendar_month == 12) calendar_month = 1;
else calendar_month++;
document.getElementById("months").innerHTML = month_names[calendar_month];
update_calendar();
LoadGraph(calendar_month);
}
}
function update_calendar() {
var days = document.getElementById("days");
days.innerHTML = "";
for (var i = 1; i <= month_days[calendar_month]; i++) {
days.innerHTML = days.innerHTML + "<li>" + i + "</li>\n";
}
const parentDiv = document.getElementById("days");
const childElements = parentDiv.children;
childElements[calendar_day - 1].setAttribute("class", "active");
for (const child of childElements) {
child.onclick = function () {
childElements[calendar_day - 1].removeAttribute("class");
calendar_day = parseInt(child.innerHTML);
childElements[calendar_day - 1].setAttribute("class", "active");
console.log("Pressed days" + child.innerHTML);
if (document.getElementById("title_dashboard").innerHTML != "Dashboard") {
ShowDetail(calendar_month * 100 + calendar_day);
}
}
}
ShowDetail(calendar_month*100 + calendar_day);
}
function getidx(date) {
if (date < 200) return date - 101;
if (date < 300) return date - 170;
if (date < 400) return date - 241;
if (date < 500) return date - 310;
if (date < 600) return date - 380;
if (date < 700) return date - 449;
if (date < 800) return date - 519;
if (date < 900) return date - 588;
if (date < 1000) return date - 657;
if (date < 1100) return date - 727;
if (date < 1200) return date - 796;
return date - 866;
}
function ShowDetail(date) {
data = wdata[getidx(date)];
console.log(data)
document.getElementById("temp").innerHTML = " max:" + (data["maxTemp"] - 273.15).toFixed(2) + "°C<br /> min:" + (data["minTemp"] - 273.15).toFixed(2) + "°C<br /> mean:" + (data["meanTemp"] - 273.15).toFixed(2) + "°C";
document.getElementById("clouds").innerHTML = " max:" + data["maxclouds"] + "%<br /> min:" + data["minclouds"] + "%<br /> mean:" + data["meanclouds"] + "%";
document.getElementById("wind").innerHTML = " max:" + data["maxwind"] + "m/s<br /> min:" + data["minwind"] + "m/s<br /> mean:" + data["meanwind"] + "m/s";
document.getElementById("pressure").innerHTML = " max:" + data["maxpressure"] + "Pa<br /> min:" + data["minpressure"] + "Pa<br /> mean:" + data["meanpressure"] + "Pa";
document.getElementById("ppt").innerHTML = " max:" + data["maxppt"] + "mm<br /> min:" + data["minppt"] + "mm<br /> mean:" + data["meanppt"] + "mm";
document.getElementById("humidity").innerHTML = " max:" + data["maxhumidity"] + "%<br /> min:" + data["minhumidity"] + "%<br /> mean:" + data["meanhumidity"] + "%";
document.getElementById("title_dashboard").innerHTML = "Dashboard - " + data["cityname"];
}
function LoadGraph(month) {
/*if(!linegraph_init) {
init_LineGraph();
linegraph_init = true;
console.log("line graph init");
}*/
document.getElementById("LinerGraph").innerHTML = "";
var data = [];
var idx = 1;
for (var i = getidx(month * 100 + 1); i < getidx((month + 1) * 100 + 1); i++) {
data.push([idx.toString(), wdata[i]["meanTemp"] - 273.15, wdata[i]["meanclouds"], wdata[i]["meanppt"], wdata[i]["meanpressure"] / 1000, wdata[i]["meanhumidity"], wdata[i]["meanwind"]]);
idx++;
}
var dataSet = anychart.data.set(data);
// map data for the first series,
// take x from the zero column and value from the first column
var firstSeriesData = dataSet.mapAs({ x: 0, value: 1 });
// map data for the second series,
// take x from the zero column and value from the second column
var secondSeriesData = dataSet.mapAs({ x: 0, value: 2 });
// map data for the third series,
// take x from the zero column and value from the third column
var thirdSeriesData = dataSet.mapAs({ x: 0, value: 3 });
// map data for the fourth series,
// take x from the zero column and value from the fourth column
var fourthSeriesData = dataSet.mapAs({ x: 0, value: 4 });
var fifthSeriesData = dataSet.mapAs({ x: 0, value: 5 });
var sixthSeriesData = dataSet.mapAs({ x: 0, value: 6 });
var chart = anychart.line();
chart.animation(true);
chart.title('Monthly Weather Trend');
chart.crosshair().enabled(true).yLabel(false).yStroke(null);
// create the first series with the mapped data
var firstSeries = chart.line(firstSeriesData);
firstSeries
.name('Temperature')
.stroke('3 #f49595')
.tooltip()
.format('Temperature : {%value}K');
// create the second series with the mapped data
var secondSeries = chart.line(secondSeriesData);
secondSeries
.name('Clouds')
.stroke('3 #f9eb97')
.tooltip()
.format('Clouds : {%value}%');
// create the third series with the mapped data
var thirdSeries = chart.line(thirdSeriesData);
thirdSeries
.name('Precipitation')
.stroke('3 #a8d9f6')
.tooltip()
.format('Precipitation : {%value}mm');
// create the fourth series with the mapped data
var fourthSeries = chart.line(fourthSeriesData);
fourthSeries
.name('Pressure')
.stroke('3 #e2bbfd')
.tooltip()
.format('Pressure : {%value}');
// create the first series with the mapped data
var fifthSeries = chart.line(fifthSeriesData);
fifthSeries
.name('Humidity')
.stroke('3 #11ff11')
.tooltip()
.format('Humidity : {%value}%');
// create the first series with the mapped data
var sixthSeries = chart.line(sixthSeriesData);
sixthSeries
.name('Wind')
.stroke('3 #222')
.tooltip()
.format('Wind : {%value}%');
// turn the legend on
chart.legend().enabled(true);
// set the container id for the line chart
chart.container('LinerGraph');
chart.width(330);
chart.height(340);
// draw the line chart
chart.draw();
}
function init_map() {
anychart.onDocumentReady(function () {
// create the dataset of points that are defined by latitude and longitude values
var data = citylistarray;
console.log(data);
document.getElementById("mapcontainer").style.display = "block";
var map = anychart.map();
// Sets geodata using https://cdn.anychart.com/geodata/latest/custom/world/world.js
map.geoData('anychart.maps.world');
// Sets Chart Title
map
.title()
.enabled(true)
.text('Cities With Weather Data')
.padding([0, 0, 20, 0]);
map.interactivity().selectionMode('none');
// Sets bubble max size settings
map.minBubbleSize('0.5%').maxBubbleSize('1.5%');
var series = map.marker(data);
map.listen('dblclick', clickcity);
function clickcity(e) {
document.getElementById("btn_dashboard").onclick();
ipcRenderer.send('GetData', citylistarray[e.pointIndex]["name"]);
}
map.interactivity().zoomOnMouseWheel(true);
/*map
.tooltip()
.background('#3A4750')
.enabled(true)
.fill('#00ADB5')
.stroke('#c1c1c1')
.corners(3)
.cornerType('round');*/
// create zoom controls
map.background().fill("#3A4750");
var zoomController = anychart.ui.zoom();
zoomController.render(map);
// Sets container id for the chart
map.container('mapcontainer');
// Initiates chart drawing
map.draw();
document.getElementById("mapcontainer").style.display = "none";
});
}