-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathWeatherWidget.vue
432 lines (368 loc) · 12.2 KB
/
WeatherWidget.vue
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
<template>
<!-- Container -->
<div id="weather-widget" class="wcontainer p-1">
<div>
<h6>Weather and sea conditions</h6>
Date: {{currentDate}}, Latitude: {{lat}} º, Longitude: {{long}} º
</div>
<!-- Table -->
<table>
<!-- Table Head - Days -->
<thead>
<tr>
<td></td>
<!-- Col for each day -->
<th class="wcol" style='min-width: 40px' :key="dd" v-for="(dd, index) in daysString" :title="dates[index].toISOString()">
{{dd}}
</th>
</tr>
</thead>
<!-- Table body - Variables -->
<tbody>
<!-- Row -->
<tr :key="dR.name" v-for="(dR, index) in dataRows">
<!-- Row name -->
<th scope="row"><span v-show="dR.imgURL== undefined">{{dR.name}} ({{dR.units}})</span></th>
<!-- Values -->
<td class="wcol" :key="dd.key" v-for="dd in dataRows[index].data">
<div v-if='dd.loading' class="spinner-border text-dark" style="width: 1rem; height: 1rem; position: relative;" role="status">
<span class="visually-hidden">Loading...</span>
</div>
<div v-else-if='dR.direction' :style="{'transform': 'rotate('+ (-dd.value - 90) +'deg)'}" :title="dd.value + 'º'">➜</div>
<div v-else-if='dR.imgURL'><img :src=dR.defURL :alt=dR.source :style="getImageStyle(dR, dd)"></div>
<div v-else-if='!dd.loading' :style="getStyle(dR, dd)">{{dd.value}}</div>
</td>
</tr>
</tbody>
</table>
<div>
<i>Generated using E.U. Copernicus Marine Service Information; </i>
<i><a href="https://doi.org/10.25423/CMCC/MEDSEA_ANALYSISFORECAST_PHY_006_013_EAS6" target="_blank" rel="noreferrer noopener">Sea Physics Analysis and Forecast; </a></i>
<i><a href="https://doi.org/10.25423/CMCC/MEDSEA_MULTIYEAR_PHY_006_004_E3R1" target="_blank" rel="noreferrer noopener">Sea Physics Reanalysis; </a></i>
<i><a href="https://doi.org/10.25423/cmcc/medsea_analysisforecast_wav_006_017_medwam3" target="_blank" rel="noreferrer noopener">Sea Waves Analysis and Forecast; </a></i>
<i><a href="https://doi.org/10.25423/cmcc/medsea_multiyear_wav_006_012" target="_blank" rel="noreferrer noopener">Sea Waves Reanalysis; </a></i>
<i><a href="https://doi.org/10.25423/cmcc/medsea_analysisforecast_bgc_006_014_medbfm3" target="_blank" rel="noreferrer noopener">Sea Biogeochemistry Analysis and Forecast; </a></i>
<i><a href="https://doi.org/10.25423/cmcc/medsea_multiyear_bgc_006_008_medbfm3" target="_blank" rel="noreferrer noopener">Sea Biogechemistry Reanalysis; </a></i>
<i><a href="https://doi.org/10.48670/moi-00184" target="_blank" rel="noreferrer noopener">Wind L4 Near real Time; </a></i>
<i><a href="https://doi.org/10.48670/moi-00185" target="_blank" rel="noreferrer noopener">Wind L4 Reprocessed; </a></i>
</div>
</div>
</template>
<script>
export default {
// REQUIRES WMSDataRetriever.js
name: "weather-info",
created(){
// Create data retreiver
this.dataRetriever = new WMSDataRetriever();
// Create data array inside dataRows
this.dataRows.forEach(dr => {
dr.data = [];
for (let i = 0; i < this.numDays; i++)
dr.data[i] = {value: '', loading: true, key: dr.name ? dr.name + i : dr.key + i};
});
// Update table
this.updateTable(new Date(2020, 10, 12), 40.78, 0.98); // Preselected track
},
mounted(){
},
unmounted(){
},
data(){
return {
// Check https://es.wisuki.com/spot/2617/barceloneta for inspiration
dataRows: [
{ // Wind icon
key: 'windicon',
imgURL: 'icons.png',
position: 0,
defURL: 'data/emptyPixel.png',
source: 'Wind',
signRange: [5,15],
color: '#6164ff',
},
{
name: "Wind direction",
abbr: "Dir",
units: "º",
direction: true,
layer: "Wind",
},
{
name: "Wind",
abbr: "Wind",
icon: true,
units: "m/s",
range: [0, 30],
signRange: [5,15],
color: '#6164ff',//'#71c3eb',
colorScale: 'boxfill/sst_36'
},
{ // Wave icon
key: 'waveicon',
imgURL: 'icons.png',
position: 1,
defURL: 'https://es.wisuki.com/images/px.png',
source: 'Wave significant height',
signRange: [1, 4],
color: '#6164ff',
},
{
name: "Wave direction",
abbr: "Dir",
units: "º",
direction: true,
layer: "Wave significant height",
},
{
name: "Wave significant height",
abbr: "Waves",
icon: true,
units: "m",
range: [0, 8],
signRange: [0.2,4],
color: '#6164ff',//'#71c3eb',
colorScale: 'boxfill/alg',
},
{
name: "Wave period",
abbr: "T",
units: "s",
range: [0,25],
signRange: [6,15],
color: '#6164ff' // TODO: color or colorScale. If color, go from transparent to the specified color.
},
{ // Current icon
key: 'currenticon',
imgURL: 'icons.png',
position: 2,
defURL: 'https://es.wisuki.com/images/px.png',
source: 'Sea surface velocity',
signRange: [0.25, 1],
color: '#6164ff',
},
{
name: "Sea current direction",
abbr: "Dir",
units: "m/s",
direction: true,
layer: "Sea surface velocity",
color: '#6164ff',//'#71c3eb',
}, {
name: "Sea surface velocity",
abbr: "Current",
icon: true,
units: "m/s",
range: [0, 3],
signRange: [0.25, 1],
color: '#6164ff',//'#71c3eb',
},
{
name: "Chlorophyll",
abbr: "Chl",
units: "mg/m3",
range: [0, 2.5],
signRange: [0.5,1],
color: '#6164ff'
},
{
name: "Salinity",
abbr: "Sal",
units: "‰",
range: [30, 45],
signRange: [38, 40],
color: '#6164ff'
},
{
name: "Sea temperature",
abbr: "Sea t",
units: 'ºC',
elevation: true, // TODO: ALLOWS 2D PLOT IF CLICKED ON THE VARIABLE NAME ▼?
range: [10, 25],
colorScale: 'boxfill/sst_36',
},
{
name: "Sea bottom temperature",
abbr: "Bottom t",
units: 'ºC',
range: [10, 25],
colorScale: 'boxfill/sst_36'
},
],
numDays: 7,
daysString: [],
currentDate: '',
lat: '',
long: '',
}
},
methods: {
// USER HTML ACTIONS
onClick: function(event){
},
// PRIVATE METHODS
getData: function(lat, long){
// Get data
this.dataRows.forEach((rr, rIndex) => {
this.dates.forEach((date, dIndex) => {
let layerName = rr.direction ? rr.layer : rr.name;
// Icon row does not load data
if (layerName !== undefined){
this.dataRetriever.getDataAtPoint(layerName, date.toISOString(), lat, long, 'd', rr.direction)
.then(value => {
if (value == undefined){
rr.data[dIndex].value = 'x';
rr.data[dIndex].loading = false;
return;
}
rr.data[dIndex].value = value.toFixed(2);
rr.data[dIndex].loading = false;
// Icon
if (rr.icon){
// Find dataRow with source
let iconRow = this.dataRows.filter(e => e.source == rr.name)[0];
if (iconRow == undefined) {console.error('Icon is not found for ' + rr.name); return};
iconRow.data[dIndex].value = rr.data[dIndex].value;
iconRow.data[dIndex].loading = false;
}
})
.catch(error => {
console.error(error);
rr.data[dIndex].value = 'x';
rr.data[dIndex].loading = false;
});
} // end of if
});
})
},
getStyle: function(dR, dd){
let color = dR.color;
let range = dR.signRange ? dR.signRange : dR.range; // Significant range
let value = dd.value;
let alpha = value == 'x' ? 0 : 255*(value - range[0]) / (range[1] - range[0]);
alpha = Math.max(Math.min(alpha, 255), 0); // Clamp for HEX conversion
let textWeight = 'normal';
if (dR.signRange){
if (value > (range[0] + 0.33*(range[1]-range[0])))
textWeight = 'bold';
else if (value > (range[0] + 0.66*(range[1]-range[0])))
textWeight = 'bolder';
}
return {
'background-color': color + alpha.toString(16).split('.')[0],
'font-weight': textWeight,
'border-radius': '4px',
}
},
// Create image style
getImageStyle: function(dR, dd){
let color = dR.color;
let range = dR.signRange ? dR.signRange : dR.range; // Significant range
let value = dd.value;
let alpha = value == 'x' ? 0 : (value - range[0]) / (range[1] - range[0]);
alpha = Math.max(Math.min(alpha, 1), 0); // Clamp for HEX conversion
//alpha *= 255;
let colorFactor = 0;
if (alpha == 0)
colorFactor = 0;
else if (alpha < 0.33)
colorFactor = 1;
else if (alpha < 0.66)
colorFactor = 2;
else
colorFactor = 3;
let cssPosition = -dR.position*32 - colorFactor * 32*3;
// if (alpha/255 == 0){
// color = '#9cc6c8';
// } else if (alpha/255 < 0.33){
// color = '#1fcf02';
// } else if (alpha/255 < 0.66){
// color = '#da9000';
// } else {
// color = '#e03636';
// }
// // Create linear gradient
// let linGrad = 'linear-gradient(0deg, ' + color + '66 0%, ' + color + 'ff 100%)'
return {
//'background': color + alpha.toString(16).split('.')[0],
'background-image': 'url('+ dR.imgURL +')',
'background-position': cssPosition + 'px 0',
transform: 'scale(1)',
}
},
// Create dates
createDates: function(inputDate) {
// If dates does not exists (initialization)
this.dates = this.dates == undefined ? this.dates = [] : this.dates;
for (let i = 0; i < this.numDays; i++){
this.daysString[this.numDays-1 - i] = inputDate.toDateString().substring(0,2) + ' ' + inputDate.getDate();
this.dates[this.numDays-1 - i] = new Date(inputDate.getTime());
inputDate.setDate(inputDate.getDate() - 1);
}
},
// PUBLIC METHODS
updateTable: function(inputDate, lat, long){
this.lat = lat.toFixed(2);
this.long = long.toFixed(2);
this.currentDate = inputDate.toString().substring(0,15);
// Reset loading
this.dataRows.forEach(dr => {
for (let i = 0; i < this.numDays; i++){
dr.data[i].value = '';
dr.data[i].loading = true;
}
});
// Create dates
this.createDates(inputDate);
// Cancel active requests
this.dataRetriever.cancelActiveRequests();
// Update data
this.getData(lat, long);
}
},
components: {
},
computed: {
}
}
</script>
<style scoped>
.wcontainer {
font-size:12px;
/* display: flex;
flex-direction: column; */
width: 100%;
/* border:black;
border-style: solid; */
}
.wrow {
/* display: flex;
flex-direction: row; */
/* border:rgb(95, 95, 95);
border-style: solid; */
text-align: center;
}
.wcol {
/* border:rgb(252, 252, 252);
border-style: solid; */
border-style:none;
/* flex-grow: 1; */
text-align: center;
align-items: center;
padding: 2px;
}
img {
border-radius: 9px;
width: 32px;
height: 32px;
background-repeat: no-repeat;
}
/* unvisited link */
a:link { color: #808080; }
/* visited link */
a:visited { color: #808080; }
/* mouse over link */
a:hover { color: #424242; }
/* selected link */
a:active { color: #000000; }
</style>