1
|
import { MapCountryData } from '../../domain/map-country-data';;
|
2
|
|
3
|
import { Component, EventEmitter, OnInit, Output } from '@angular/core';
|
4
|
import { CountryOverview } from '../../domain/overview-data';
|
5
|
|
6
|
import { DataService } from '../../services/data.service';
|
7
|
import { Router } from '@angular/router';
|
8
|
import {CountryMapData, JoinedMapData, OverviewMapData, SelectedCountry} from '../../domain/overview-map-data';
|
9
|
import { latlong } from '../../domain/countries-lat-lon';
|
10
|
import { DataHandlerService } from '../../services/data-handler.service';
|
11
|
|
12
|
import * as echarts from 'echarts';
|
13
|
|
14
|
declare var require: any;
|
15
|
|
16
|
const mapWorld = require('echarts/map/json/world.json');
|
17
|
|
18
|
@Component({
|
19
|
selector: 'app-europe-map-overview',
|
20
|
templateUrl: './europe-map-overview.component.html',
|
21
|
})
|
22
|
|
23
|
export class EuropeMapOverviewComponent implements OnInit {
|
24
|
|
25
|
countries: CountryOverview[];
|
26
|
|
27
|
@Output() emitSelectedCountry: EventEmitter<any> = new EventEmitter();
|
28
|
|
29
|
activeView: string = 'publications';
|
30
|
seriesColor: string = '#F17AA9';
|
31
|
seriesName: string = 'OA publications';
|
32
|
|
33
|
// tooltipBackgroundColor: string = '#EC4386';
|
34
|
tooltipBackgroundColor: string = '#a52e5d';
|
35
|
tooltipBorderColor: string = '#000';
|
36
|
|
37
|
options = {};
|
38
|
|
39
|
overviewMapData: OverviewMapData;
|
40
|
|
41
|
countriesLatLong = latlong;
|
42
|
|
43
|
joinedPublicationsMap: Map<string, JoinedMapData>;
|
44
|
joinedDatasetsMap: Map<string, JoinedMapData>;
|
45
|
|
46
|
constructor(private dataService: DataService,
|
47
|
private dataHandlerService: DataHandlerService,
|
48
|
private router: Router) {}
|
49
|
|
50
|
ngOnInit(): void {
|
51
|
|
52
|
echarts.registerMap('world', mapWorld);
|
53
|
|
54
|
if (this.isEmbedRoute()) {
|
55
|
const body = document.getElementsByTagName('body')[0];
|
56
|
body.classList.remove('header_sticky');
|
57
|
}
|
58
|
|
59
|
this.dataService.getOverviewMapData().subscribe(
|
60
|
rawData => {
|
61
|
// console.log('==== Map RawData ====', rawData);
|
62
|
this.overviewMapData = this.dataHandlerService.convertRawMapDataToMapData(rawData);
|
63
|
this.joinedPublicationsMap = this.dataHandlerService.createJoinedPublicationsCountryMap(rawData);
|
64
|
this.joinedDatasetsMap = this.dataHandlerService.createJoinedDatasetsCountryMap(rawData);
|
65
|
|
66
|
// console.log('Country map data', this.overviewMapData[this.activeView]);
|
67
|
this.loadMap(this.overviewMapData[this.activeView], this.seriesColor, this.seriesColor);
|
68
|
},
|
69
|
error => {
|
70
|
console.log(error);
|
71
|
}
|
72
|
);
|
73
|
}
|
74
|
|
75
|
changeView(view: string) {
|
76
|
this.activeView = view;
|
77
|
|
78
|
if (this.activeView === 'publications') {
|
79
|
this.seriesColor = '#F17AA9';
|
80
|
this.seriesName = 'OA publications';
|
81
|
this.tooltipBackgroundColor = '#a52e5d';
|
82
|
this.tooltipBorderColor = '#000';
|
83
|
} else if (this.activeView === 'datasets') {
|
84
|
this.seriesColor = '#A98BD4';
|
85
|
this.seriesName = 'OA datasets';
|
86
|
this.tooltipBackgroundColor = '#7658a1';
|
87
|
this.tooltipBorderColor = '#000';
|
88
|
} else if (this.activeView === 'repositories') {
|
89
|
this.seriesColor = '#708AA5';
|
90
|
this.seriesName = 'OA repositories';
|
91
|
this.tooltipBackgroundColor = '#3d5772';
|
92
|
this.tooltipBorderColor = '#000';
|
93
|
} else if (this.activeView === 'journals') {
|
94
|
this.seriesColor = '#FFCE4E';
|
95
|
this.seriesName = 'OA journals';
|
96
|
this.tooltipBackgroundColor = '#cc9b1b';
|
97
|
this.tooltipBorderColor = '#000';
|
98
|
} else {
|
99
|
this.seriesColor = '#639C66';
|
100
|
this.seriesName = 'OA policies';
|
101
|
this.tooltipBackgroundColor = '#306933';
|
102
|
this.tooltipBorderColor = '#000';
|
103
|
}
|
104
|
this.loadMap(this.overviewMapData[view], this.seriesColor, this.seriesName);
|
105
|
}
|
106
|
|
107
|
loadMap(countryMapData: CountryMapData[], seriesColor: string, seriesName: string) {
|
108
|
|
109
|
this.options = {
|
110
|
title : {
|
111
|
// text: 'World Population (2011)',
|
112
|
// subtext: 'From Gapminder',
|
113
|
left: 'center',
|
114
|
top: 'top',
|
115
|
textStyle: {
|
116
|
color: '#fff'
|
117
|
}
|
118
|
},
|
119
|
responsive: true,
|
120
|
tooltip : {
|
121
|
trigger: 'item',
|
122
|
// position: 'top',
|
123
|
// formatter: '<strong>{b}</strong><br> {c2} {a}',
|
124
|
// backgroundColor: '#f6c4d8',
|
125
|
// borderColor: '#bf1d5e',
|
126
|
// borderWidth: 0.2
|
127
|
},
|
128
|
visualMap: {
|
129
|
show: false,
|
130
|
min: 0,
|
131
|
// max: max,
|
132
|
max: 80000,
|
133
|
inRange: {
|
134
|
// symbolSize: [6, 60]
|
135
|
// symbolSize: [0, 6]
|
136
|
}
|
137
|
},
|
138
|
geo: {
|
139
|
// name: 'World Population (2010)',
|
140
|
type: 'map',
|
141
|
map: 'world',
|
142
|
// center: [15.2551, 54.5260],
|
143
|
center: [14, 51],
|
144
|
zoom: 4.7,
|
145
|
// roam: true,
|
146
|
label: {
|
147
|
emphasis: {
|
148
|
show: false
|
149
|
}
|
150
|
},
|
151
|
itemStyle: {
|
152
|
normal: {
|
153
|
// color: 'rgba(139,151,167,0.4)',
|
154
|
// borderColor: '#000',
|
155
|
borderColor: '#fff',
|
156
|
borderWidth: 0.5,
|
157
|
areaColor: 'rgba(139,151,167,0.6)',
|
158
|
// areaStyle: {
|
159
|
// color: 'rgba(139,151,167,0.2)'
|
160
|
// }
|
161
|
},
|
162
|
emphasis: {
|
163
|
// color: 'rgba(139,151,167,0.4)',
|
164
|
// borderColor: '#000',
|
165
|
borderColor: '#fff',
|
166
|
borderWidth: 0.5,
|
167
|
areaColor: 'rgba(139,151,167,0.8)',
|
168
|
// areaStyle: {
|
169
|
// color: 'rgba(139,151,167,0.2)'
|
170
|
// }
|
171
|
}
|
172
|
}
|
173
|
// itemStyle: {
|
174
|
// // areacolor: '#ffffff',
|
175
|
// // bordercolor: '#111',
|
176
|
// // borderWidth: 1,
|
177
|
// // normal: {
|
178
|
// // // areacolor: '#323c48',
|
179
|
// // areacolor: '#ffffff',
|
180
|
// // bordercolor: '#111'
|
181
|
// // },
|
182
|
// // emphasis: {
|
183
|
// // areacolor: '#2a333d'
|
184
|
// // }
|
185
|
// }
|
186
|
},
|
187
|
series : [
|
188
|
{
|
189
|
type: 'scatter',
|
190
|
coordinateSystem: 'geo',
|
191
|
name: seriesName,
|
192
|
label: {
|
193
|
show: true,
|
194
|
position: 'inside',
|
195
|
color: '#fff',
|
196
|
opacity: 1,
|
197
|
// formatter: '{@[2]}',
|
198
|
formatter: (params => {
|
199
|
return params.data.value[2].toLocaleString();
|
200
|
}),
|
201
|
textBorderColor: '#000',
|
202
|
textBorderWidth: '2',
|
203
|
fontSize: 15
|
204
|
// formatter: '{b}: {@score}'
|
205
|
},
|
206
|
// activeOpacity: 0.6,
|
207
|
data: countryMapData.map((itemOpt) => {
|
208
|
// console.log('itemOpt.code', itemOpt.code);
|
209
|
return {
|
210
|
name: itemOpt.name,
|
211
|
value: [
|
212
|
this.countriesLatLong.get(itemOpt.code).longitude,
|
213
|
this.countriesLatLong.get(itemOpt.code).latitude,
|
214
|
itemOpt.value
|
215
|
],
|
216
|
// label: {
|
217
|
// emphasis: {
|
218
|
// position: 'right',
|
219
|
// show: true
|
220
|
// }
|
221
|
// },
|
222
|
itemStyle: {
|
223
|
normal: {
|
224
|
color: seriesColor,
|
225
|
// color: '#f8d5e3',
|
226
|
// opacity: 0.8,
|
227
|
borderColor: seriesColor,
|
228
|
borderWidth: 2
|
229
|
}
|
230
|
}
|
231
|
};
|
232
|
}),
|
233
|
symbolSize: value => {
|
234
|
// console.log('Math.sqrt(value[2]) / 1000: ' + (Math.sqrt(value[2]) / 1000) );
|
235
|
// return Math.sqrt(value[2]) / 10;
|
236
|
return Math.sqrt(value[2]) / 10 * this.resizeFactor(countryMapData);
|
237
|
// return Math.sqrt(value[2]) / 10;
|
238
|
},
|
239
|
tooltip : {
|
240
|
trigger: 'item',
|
241
|
position: 'top',
|
242
|
formatter: (params => {
|
243
|
// console.log('params: ', params);
|
244
|
// let bla = '<strong>' + params.data.name + '</strong><br>';
|
245
|
// bla += params.data.value[2].toLocaleString() + ' ' + params.seriesName;
|
246
|
// return bla;
|
247
|
return this.createTooltip(params);
|
248
|
}),
|
249
|
backgroundColor: this.tooltipBackgroundColor,
|
250
|
borderColor: this.tooltipBorderColor,
|
251
|
borderWidth: 0.2
|
252
|
},
|
253
|
}
|
254
|
]
|
255
|
};
|
256
|
}
|
257
|
|
258
|
onChartClick(event: any, type: string) {
|
259
|
// console.log('chart event:', type, event);
|
260
|
// console.log('country:', event.name);
|
261
|
|
262
|
const selectedCountry: SelectedCountry = new SelectedCountry();
|
263
|
selectedCountry.name = event.name;
|
264
|
selectedCountry.code = this.joinedPublicationsMap.get(event.name).countryCode;
|
265
|
|
266
|
// console.log('Selected country', selectedCountry);
|
267
|
this.emitSelectedCountry.emit(selectedCountry);
|
268
|
}
|
269
|
|
270
|
// selectedCountry(countryName: string) {
|
271
|
// this.emitSelectedCountry.emit(countryName);
|
272
|
// }
|
273
|
|
274
|
isEmbedRoute() {
|
275
|
return (this.router.url === '/overview-map-embed');
|
276
|
}
|
277
|
|
278
|
resizeFactor(countryMapData: CountryMapData[]) {
|
279
|
|
280
|
let max = 0;
|
281
|
for (const countryData of countryMapData) {
|
282
|
if (countryData.value > max) {
|
283
|
max = countryData.value;
|
284
|
}
|
285
|
}
|
286
|
// console.log('resizeFactor', 100 / (Math.sqrt(max) / 10));
|
287
|
return 100 / (Math.sqrt(max) / 10);
|
288
|
}
|
289
|
|
290
|
createTooltip(params: any) {
|
291
|
|
292
|
// console.log('params: ', params);
|
293
|
// console.log('params.name: ', params.name);
|
294
|
|
295
|
let tooltip = '<div style="padding:10px">';
|
296
|
|
297
|
tooltip += '<div class="uk-margin-small" style="font-weight: 600;">' + params.name + '</div>';
|
298
|
|
299
|
if (this.activeView === 'publications') {
|
300
|
|
301
|
tooltip += '<div class="numbers">';
|
302
|
tooltip += '<div class="indicator">' +
|
303
|
'<span class="number">' + params.data.value[2].toLocaleString() + '</span>' +
|
304
|
'<span><i>OA publications</i> affiliated <br>to an organization in the country</span></div>';
|
305
|
|
306
|
tooltip += '<div class="indicator uk-margin-small-top">' +
|
307
|
'<span class="number">' + this.joinedPublicationsMap.get(params.name).deposited.toLocaleString() + '</span>' +
|
308
|
'<span><i>OA publications</i> from <br>institutional repositories</span></div>';
|
309
|
|
310
|
tooltip += '</div>';
|
311
|
|
312
|
} else if (this.activeView === 'datasets') {
|
313
|
|
314
|
tooltip += '<div class="numbers">';
|
315
|
tooltip += '<div class="indicator">' +
|
316
|
'<span class="number">' + params.data.value[2].toLocaleString() + '</span>' +
|
317
|
'<span><i>OA datasets</i> affiliated <br>to an organization in the country</span></div>';
|
318
|
|
319
|
tooltip += '<div class="indicator uk-margin-small-top">' +
|
320
|
'<span class="number">' + this.joinedDatasetsMap.get(params.name).deposited.toLocaleString() + '</span>' +
|
321
|
'<span><i>OA datasets</i> from <br>institutional repositories</span></div>';
|
322
|
|
323
|
tooltip += '</div>';
|
324
|
|
325
|
} else if (this.activeView === 'repositories') {
|
326
|
|
327
|
tooltip += '<div class="numbers">';
|
328
|
tooltip += '<div class="indicator">' +
|
329
|
'<span class="number">' + params.data.value[2].toLocaleString() + '</span>' +
|
330
|
'<span><i>repositories</i> from <br>openDOAR & re3data</span></div>';
|
331
|
|
332
|
tooltip += '</div>';
|
333
|
|
334
|
} else if (this.activeView === 'journals') {
|
335
|
|
336
|
tooltip += '<div class="numbers">';
|
337
|
tooltip += '<div class="indicator">' +
|
338
|
'<span class="number">' + params.data.value[2].toLocaleString() + '</span>' +
|
339
|
'<span><i>journals</i> from <br>DOAJ</span></div>';
|
340
|
|
341
|
tooltip += '</div>';
|
342
|
|
343
|
} else {
|
344
|
|
345
|
tooltip += '<div class="numbers">';
|
346
|
tooltip += '<div class="indicator">' +
|
347
|
'<span class="number">' + params.data.value[2].toLocaleString() + '</span>' +
|
348
|
'<span>organizations with <br><i>OA policies</i></span></div>';
|
349
|
|
350
|
tooltip += '</div>';
|
351
|
}
|
352
|
|
353
|
tooltip += '</div>';
|
354
|
return tooltip;
|
355
|
}
|
356
|
}
|