-
Notifications
You must be signed in to change notification settings - Fork 0
/
bundle.js
578 lines (549 loc) · 14.1 KB
/
bundle.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
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
/**
* Data for side menu
*
* @author Yauheni Svirydzenka <[email protected]>
* @version 0.0.1
* @copyright Yauheni Svirydzenka 2017
*/
var citiesData = [
{
id: "asipovichi",
value: "Asipovichi",
icon: "retweet"
},
{
id: "baranavichy",
value: "Baranavichy",
icon: "train"
},
{
id: "barysaw",
value: "Barysaw",
icon: "futbol-o"
},
{
id: "bobruysk",
value: "Bobruysk",
icon: "gear"
},
{
id: "braslav",
value: "Braslav",
icon: "road"
},
{
id: "brest",
value: "Brest",
icon: "arrows-v"
},
{
id: "gorki",
value: "Gorki",
icon: "university"
},
{
id: "grodno",
value: "Grodno",
icon: "building"
},
{
id: "homyel",
value: "Homyel",
icon: "truck"
},
{
id: "kalinkavichi",
value: "Kalinkavichi",
icon: "save"
},
{
id: "kobrin",
value: "Kobrin",
icon: "bed"
},
{
id: "krichev",
value: "Krichev",
icon: "dashboard"
},
{
id: "lida",
value: "Lida",
icon: "key"
},
{
id: "lyepyel'",
value: "Lyepyel'",
icon: "leaf"
},
{
id: "mahilyow",
value: "Mahilyow",
icon: "tty"
},
{
id: "maladzyechna",
value: "Maladzyechna",
icon: "cloud"
},
{
id: "mazyr",
value: "Mazyr",
icon: "fire-extinguisher"
},
{
id: "minsk",
value: "Minsk",
icon: "send"
},
{
id: "navapolatsk",
value: "Navapolatsk",
icon: "bank"
},
{
id: "niasvizh",
value: "Niasvizh",
icon: "certificate"
},
{
id: "orsha",
value: "Orsha",
icon: "plus"
},
{
id: "pinsk",
value: "Pinsk",
icon: "arrows-h"
},
{
id: "polatsk",
value: "Polatsk",
icon: "anchor"
},
{
id: "rechytsa",
value: "Rechytsa",
icon: "random"
},
{
id: "rogachev",
value: "Rogachev",
icon: "tag"
},
{
id: "salihorsk",
value: "Salihorsk",
icon: "signal"
},
{
id: "slutsk",
value: "Slutsk",
icon: "stop"
},
{
id: "smarhon",
value: "Smarhon",
icon: "inbox"
},
{
id: "svetlagorsk",
value: "Svetlagorsk",
icon: "sun-o"
},
{
id: "vaukavysk",
value: "Vaukavysk",
icon: "camera"
},
{
id: "vitsyebsk",
value: "Vitsyebsk",
icon: "user"
},
{
id: "zhlobin",
value: "Zhlobin",
icon: "bullhorn"
},
{
id: "zhodzina",
value: "Zhodzina",
icon: "tags"
}
];
/**
* Main app logic
*
* @author Yauheni Svirydzenka <[email protected]>
* @version 0.0.1
* @copyright Yauheni Svirydzenka 2017
*/
/**
* Set data for google map
*
* @param {object} weatherData Whole data from server
*/
function setDataForGoogleMap(weatherData) {
var lat = weatherData.item.lat;
var long = weatherData.item.long;
var center = [];
center.push(lat);
center.push(long);
$$("googleMap").define("center", center);
var marker = {
lat: lat,
lng: long,
title: "<b>City:</b> " + weatherData.location.city + "<br/><b>Country:</b> " + weatherData.location.country
};
$$("googleMap").add(marker);
}
/**
* Choose arrow class for rendering wind direction
*
* @param {object} weatherData Whole data from server
* @return {string} arrowClass Class name for arrow image
*/
function getClassForWindDirection(weatherData) {
var arrowClass = "";
var degrees = weatherData.wind.direction * 1;
if (degrees <= 23 && degrees > 338) {
arrowClass = "north";
} else if (degrees > 23 && degrees <= 68) {
arrowClass = "north-east";
} else if (degrees > 68 && degrees <= 113) {
arrowClass = "east";
} else if (degrees > 113 && degrees <= 158) {
arrowClass = "south-east";
} else if (degrees > 158 && degrees <= 203) {
arrowClass = "south";
} else if (degrees > 203 && degrees <= 248) {
arrowClass = "south-west";
} else if (degrees > 248 && degrees <= 293) {
arrowClass = "west";
} else if (degrees > 293 && degrees <= 338) {
arrowClass = "north-west";
} else {
arrowClass = "north";
}
return arrowClass;
}
/**
* Set data and render page components
*
* @param {object} weatherData Whole data from server
* @param {string} cityName City name
*/
function setDataToPageComponents(weatherData, cityName) {
var placeCountry = "<div class=\"alert alert-info\">Country: <b>" + weatherData.location.country + "</b></div>";
var placeRegion = "<div class=\"alert alert-info\">Region: <b>" + weatherData.location.region + "</b></div>";
var placeCity = "<div class=\"alert alert-info\">City: <b>" + weatherData.location.city + "</b></div>";
var wholePlaceInfo = placeCountry + placeRegion + placeCity;
$$("placeInfo").define("template", wholePlaceInfo);
$$("placeInfo").refresh();
var geoInfoSunrise = "<div class=\"alert alert-success\">Sunrise: <b>" + weatherData.astronomy.sunrise + "</b></div>";
var geoInfoSunset = "<div class=\"alert alert-success\">Sunset: <b>" + weatherData.astronomy.sunset + "</b></div>";
var geoInfoMood = "<div class=\"alert alert-success\">Mood: <b>" + weatherData.item.condition.text + "</b></div>";
var wholeGeoInfo = geoInfoSunrise + geoInfoSunset + geoInfoMood;
$$("geoInfo").define("template", wholeGeoInfo);
$$("geoInfo").refresh();
var visibility = "<div class=\"alert alert-warning\">Visibility: <b>" + weatherData.atmosphere.visibility + " km</b></div>";
var humidity = "<div class=\"alert alert-warning\">Humidity: <b>" + weatherData.atmosphere.humidity + " %</b></div>";
var windSpeedMS = (weatherData.wind.speed * 1000 / 3600).toFixed(1);
var windDirectionClass = getClassForWindDirection(weatherData);
var windDirectionImageName = "arrow";
var windDirectionImageTemplate = '<img src="images/' + windDirectionImageName + '.png" class="' + windDirectionClass + '"/>';
var wind = "<div class=\"alert alert-warning\">Wind: <b>" + windSpeedMS + " m/s</b> " + windDirectionImageTemplate + "</div>";
var wholeMeteoInfo = visibility + humidity + wind;
$$("meteoInfo").define("template", wholeMeteoInfo);
$$("meteoInfo").refresh();
var cityPhotoTemplate = '<img src="images/' + cityName + '.jpg"/>';
$$("cityPhoto").define("template", cityPhotoTemplate);
$$("cityPhoto").refresh();
var labelLatTemplate = "<span class=\"label label-info\">Latitude: " + weatherData.item.lat + "</span>";
$$("labelLat").define("label", labelLatTemplate);
$$("labelLat").refresh();
var labelLongTemplate = "<span class=\"label label-info\">Longitude: " + weatherData.item.long + "</span>";
$$("labelLong").define("label", labelLongTemplate);
$$("labelLong").refresh();
setDataForGoogleMap(weatherData);
var chartForecast = $$("chartForecast").$view;
chartForecast.setAttribute("id", "chartForecastContainer");
setChartData(weatherData.item.forecast, weatherData.location.city);
}
/**
* Handle choosing item in side menu and get data from Yahoo server
*
* @param {string} cityName City name
* @param {object} e Event
* @param {object} node Element
*/
function getWeatherByCityWoeid(cityName, e, node) {
webix.ajax().headers({
"Content-Type": "application/json"
}).post("http://localhost:4488/data", {"cityName": cityName},
function(text, data, XmlHttpRequest) {
var data = JSON.parse(text);
weatherData = data.query.results.channel;
console.log(weatherData);
setDataToPageComponents(weatherData, cityName);
});
}
/**
* Set data and render chart
*
* @param {object} forecastData Data for chart
* @param {string} city City name
*/
function setChartData(forecastData, city) {
var categories = [];
var highTemp = [];
var lowTemp = [];
forecastData.forEach(function(item, i, arr) {
categories.push(item.day + " " + item.date);
highTemp.push(+item.high);
lowTemp.push(+item.low);
});
$('#chartForecastContainer').highcharts({
chart: {
type: 'column'
},
title: {
text: '10 days weather forecast for ' + city
},
subtitle: {
text: 'Source: Yahoo Weather'
},
xAxis: {
categories: categories
},
yAxis: {
tickInterval: 1,
title: {
text: 'Temperature °C'
}
},
tooltip: {
headerFormat: '<span style="font-size:10px">{point.key}</span><table>',
pointFormat: '<tr><td style="color:{series.color};padding:0">{series.name}: </td>' +
'<td style="padding:0"><b>{point.y:.1f} °C</b></td></tr>',
footerFormat: '</table>',
shared: true,
useHTML: true
},
plotOptions: {
column: {
pointPadding: 0.2,
borderWidth: 0
}
},
series: [
{
name: 'Highest',
color: '#F00',
data: highTemp
}, {
name: 'Lowest',
color: '#00F',
data: lowTemp
}
]
});
}
/**
* Main app structure
*
* @author Yauheni Svirydzenka <[email protected]>
* @version 0.0.1
* @copyright Yauheni Svirydzenka 2017
*/
/**
* Create main layout
*/
webix.ready(function(){
webix.ui({
rows:[
{
view: "toolbar",
id: "toolbar",
elements: [
{
view: "icon",
icon: "bars",
click: function() {
if( $$("menu").config.hidden) {
$$("menu").show();
} else {
$$("menu").hide();
}
}
},
{
view: "label",
label: "Weather forecast"
},
{
view: "label",
id: "labelLat",
align: "right",
width: 180,
label: ""
},
{width: 10},
{
view: "label",
id: "labelLong",
align: "right",
width: 180,
label: ""
},
{width: 20},
{
view: "button",
id: "resetPins",
type: "iconButton",
label: "Remove map markers",
icon: "flag",
width: 185,
click: function() {
$$("googleMap").clearAll();
}
},
{
view: "button",
id: "exportToPNG",
type: "iconButton",
label: "Export to PNG",
icon: "image",
width: 140,
click: function() {
webix.toPNG($$("infoContainer"), "current_weather.png");
}
}
]
},
{
view: "layout",
cols:[
{
template: "<img src=\"images/snow.jpg\"/>",
css:"underMenu",
width: 200
},
{
rows:[
{
gravity: 3,
minHeight: 250,
cols:[
{
view: "layout",
id: "infoContainer",
minWidth: 300,
gravity: 3,
rows:[
{
view: "layout",
id: "meteoInfoContainer",
gravity: 1,
cols:[
{
id: "meteoInfo",
gravity: 1,
template: "<div class=\"alert alert-warning\">Visibility: </div><div class=\"alert alert-warning\">Humidity: </div><div class=\"alert alert-warning\">Wind: </div>",
css:"underMenu",
borderless: true
},
{
id: "geoInfo",
gravity: 1,
template: "<div class=\"alert alert-success\">Sunrise: </div><div class=\"alert alert-success\">Sunset: </div><div class=\"alert alert-danger\">Mood:</div>",
css:"underMenu",
borderless: true
}
]
},
{
view: "layout",
id: "cityInfoContainer",
gravity: 2,
cols:[
{
id: "placeInfo",
template: "<div class=\"alert alert-info\">Place info: </div>",
gravity: 1,
css:"underMenu",
borderless: true
},
{
id: "cityPhoto",
gravity: 2,
template: "<img src=\"images/placeimg_arch.jpg\"/>",
css:"underMenu",
borderless: true
},
{width: 5, css:"underMenu"}
]
},
{height: 1}
]
},
{view:"resizer"},
{
key: "AIzaSyAi0oVNVO-e603aUY8SILdD4v9bVBkmiTg",
view: "google-map",
id: "googleMap",
gravity: 2,
minWidth: 200,
zoom: 7,
center: [53.9, 27.5667]
}
]
},
{view:"resizer"},
{
gravity: 2,
view: "layout",
id: "chartForecastContainer",
minHeight: 150,
cols:[
{
id: "chartForecast",
template: "",
css:"underMenu"
}
]
}
]
}
]
}
]
});
webix.ui({
view: "sidemenu",
id: "menu",
width: 200,
position: "left",
state: function(state){
var toolbarHeight = $$("toolbar").$height;
state.top = toolbarHeight;
state.height -= toolbarHeight;
},
css: "my_menu",
body:{
view: "list",
borderless: true,
select: true,
type: {
height: 40
},
on: {
"onItemClick": getWeatherByCityWoeid
},
template: "<span class='webix_icon fa-#icon#'></span> #value#",
data: citiesData
}
}).show();
});
//# sourceMappingURL=bundle.js.map