1
|
import { MapCountryData } from '../../domain/map-country-data';
|
2
|
|
3
|
declare var require: any;
|
4
|
|
5
|
import { Component, EventEmitter, Input, OnInit, Output, ViewEncapsulation } from '@angular/core';
|
6
|
import { CountryOverview, OverviewData } from '../../domain/overview-data';
|
7
|
|
8
|
import * as Highcharts from 'highcharts';
|
9
|
import MapModule from 'highcharts/modules/map';
|
10
|
import { DataService } from '../../services/data.service';
|
11
|
import { Router } from '@angular/router';
|
12
|
|
13
|
const mapWorld = require('@highcharts/map-collection/custom/world.geo.json');
|
14
|
const mapEurope = require('@highcharts/map-collection/custom/europe.geo.json');
|
15
|
|
16
|
MapModule(Highcharts);
|
17
|
|
18
|
@Component({
|
19
|
selector: 'app-map-overview',
|
20
|
templateUrl: './countries-map-overview.component.html',
|
21
|
// styleUrls: ['./top-menu.component.css'],
|
22
|
encapsulation: ViewEncapsulation.None
|
23
|
})
|
24
|
|
25
|
export class CountriesMapOverviewComponent implements OnInit {
|
26
|
// @Input() countries: CountryOverview[];
|
27
|
|
28
|
countries: CountryOverview[];
|
29
|
|
30
|
@Output() emitSelectedCountry: EventEmitter<any> = new EventEmitter();
|
31
|
|
32
|
activeView: string = 'publications';
|
33
|
|
34
|
Highcharts: typeof Highcharts = Highcharts;
|
35
|
|
36
|
chartMapOptions: Highcharts.Options;
|
37
|
|
38
|
mapCountryData: MapCountryData[] = [];
|
39
|
seriesColor: string = '#ff9800';
|
40
|
seriesName: string = 'OA publications';
|
41
|
|
42
|
europe: string[] = [];
|
43
|
|
44
|
constructor(private dataService: DataService,
|
45
|
private router: Router) {}
|
46
|
|
47
|
ngOnInit(): void {
|
48
|
|
49
|
if (this.isEmbedRoute()) {
|
50
|
const body = document.getElementsByTagName('body')[0];
|
51
|
body.classList.remove('header_sticky');
|
52
|
}
|
53
|
|
54
|
this.dataService.getOverviewData().subscribe(
|
55
|
overviewData => {
|
56
|
this.countries = overviewData.countries;
|
57
|
this.europe = ['al', 'at', 'ba', 'be', 'by', 'bg', 'hr', 'cz', 'dk', 'ee', 'fi', 'fr', 'de', 'gr', 'hu', 'is', 'ie', 'it',
|
58
|
'lv', 'lt', 'lu', 'mk', 'mt', 'md', 'me', 'nl', 'no', 'pl', 'pt', 'ro', 'rs', 'si', 'sk', 'es', 'se', 'ch', 'tr', 'ua', 'gb'];
|
59
|
Highcharts.setOptions({
|
60
|
lang: {
|
61
|
// printChart: 'Aaaa',
|
62
|
thousandsSep: ','
|
63
|
}
|
64
|
});
|
65
|
this.loadMapCountryData();
|
66
|
this.loadMap(this.mapCountryData, this.seriesColor, this.seriesName, this.europe);
|
67
|
},
|
68
|
error => {
|
69
|
console.log(error);
|
70
|
}
|
71
|
);
|
72
|
|
73
|
// this.Highcharts.chart.get('DE').zoomTo();
|
74
|
// this.Highcharts.chart.mapZoom(0.2);
|
75
|
// this.Highcharts.get('DE').zoomTo();
|
76
|
}
|
77
|
|
78
|
changeView(view: string) {
|
79
|
this.activeView = view;
|
80
|
this.loadMapCountryData();
|
81
|
this.loadMap(this.mapCountryData, this.seriesColor, this.seriesName, this.europe);
|
82
|
// this.updateMapData();
|
83
|
}
|
84
|
|
85
|
loadMapCountryData() {
|
86
|
this.mapCountryData = [];
|
87
|
for (const index in this.countries) {
|
88
|
this.mapCountryData.push(this.overviewToMapData(this.countries[index]));
|
89
|
}
|
90
|
|
91
|
console.log(this.mapCountryData);
|
92
|
}
|
93
|
|
94
|
overviewToMapData(countryOverview: CountryOverview): MapCountryData {
|
95
|
if (this.activeView === 'publications') {
|
96
|
// this.seriesColor = '#19647E';
|
97
|
this.seriesColor = '#F17AA9';
|
98
|
this.seriesName = 'OA publications';
|
99
|
return {
|
100
|
id: countryOverview.country,
|
101
|
country: countryOverview.country,
|
102
|
z: countryOverview.publications.oa
|
103
|
};
|
104
|
} else if (this.activeView === 'datasets') {
|
105
|
this.seriesColor = '#A98BD4';
|
106
|
this.seriesName = 'OA datasets';
|
107
|
return {
|
108
|
id: countryOverview.country,
|
109
|
country: countryOverview.country,
|
110
|
z: countryOverview.datasets.oa
|
111
|
};
|
112
|
} else if (this.activeView === 'repositories') {
|
113
|
this.seriesColor = '#708AA5';
|
114
|
this.seriesName = 'OA repositories';
|
115
|
return {
|
116
|
id: countryOverview.country,
|
117
|
country: countryOverview.country,
|
118
|
z: countryOverview.repositories.oa
|
119
|
};
|
120
|
} else if (this.activeView === 'journals') {
|
121
|
this.seriesColor = '#FFCE4E';
|
122
|
this.seriesName = 'OA journals';
|
123
|
return {
|
124
|
id: countryOverview.country,
|
125
|
country: countryOverview.country,
|
126
|
z: countryOverview.journals.oa
|
127
|
};
|
128
|
} else {
|
129
|
this.seriesColor = '#639C66';
|
130
|
this.seriesName = 'OA policies';
|
131
|
return {
|
132
|
id: countryOverview.country,
|
133
|
country: countryOverview.country,
|
134
|
z: countryOverview.policies.oa
|
135
|
};
|
136
|
}
|
137
|
}
|
138
|
|
139
|
loadMap(mapCountryData: MapCountryData[], seriesColor: string, seriesName: string, countryCodes: string[]) {
|
140
|
this.chartMapOptions = {
|
141
|
chart: {
|
142
|
map: mapWorld,
|
143
|
// map: mapEurope,
|
144
|
events: {
|
145
|
load: function() {
|
146
|
this.series[0].data = this.series[0].data.map((el) => {
|
147
|
if (countryCodes.includes(el['hc-key'])) {
|
148
|
el.color = 'rgba(139,151,167,0.6)';
|
149
|
return el;
|
150
|
}
|
151
|
return el;
|
152
|
});
|
153
|
this.update({
|
154
|
series: [{
|
155
|
data: this.series[0].data as Highcharts.SeriesMapbubbleDataOptions,
|
156
|
} as Highcharts.SeriesMapbubbleOptions]
|
157
|
});
|
158
|
// this.mapZoom(0.24, 4518.24, -8188.36);
|
159
|
this.mapZoom(0.24, this.get('Germany')['x'], this.get('Germany')['y']);
|
160
|
},
|
161
|
click: event => {
|
162
|
if (event.target.hasOwnProperty('point')) {
|
163
|
console.log(event.target['point']['name']);
|
164
|
// this.selectedCountry(event.target['point']['name']);
|
165
|
}
|
166
|
}
|
167
|
}
|
168
|
},
|
169
|
lang: {
|
170
|
thousandsSep: ',',
|
171
|
decimalPoint: '.'
|
172
|
},
|
173
|
title: {
|
174
|
text: ''
|
175
|
},
|
176
|
plotOptions: {
|
177
|
series: {
|
178
|
cursor: 'pointer',
|
179
|
events: {
|
180
|
click: event => {
|
181
|
console.log(event);
|
182
|
this.countrySelected(event.point.name);
|
183
|
}
|
184
|
}
|
185
|
}
|
186
|
},
|
187
|
// subtitle: {
|
188
|
// text: 'Source map: <a href="http://code.highcharts.com/mapdata/custom/world.js">World, Miller projection, medium resolution</a>'
|
189
|
// },
|
190
|
// mapNavigation: {
|
191
|
// enabled: true,
|
192
|
// buttonOptions: {
|
193
|
// alignTo: 'spacingBox'
|
194
|
// }
|
195
|
// },
|
196
|
legend: {
|
197
|
enabled: false
|
198
|
},
|
199
|
// colorAxis: {
|
200
|
// min: 0
|
201
|
// },
|
202
|
series: [{
|
203
|
name: 'Countries',
|
204
|
borderColor: '#fff',
|
205
|
negativeColor: 'rgba(139,151,167,0.2)',
|
206
|
enableMouseTracking: false,
|
207
|
type: 'map'
|
208
|
}, {
|
209
|
name: seriesName,
|
210
|
type: 'mapbubble',
|
211
|
color: seriesColor,
|
212
|
marker: {
|
213
|
fillOpacity: 0.6,
|
214
|
// states: {
|
215
|
// hover: {
|
216
|
// fillOpacity: 0.9
|
217
|
// }
|
218
|
// }
|
219
|
},
|
220
|
joinBy: ['name', 'country'],
|
221
|
states: {
|
222
|
hover: {
|
223
|
brightness: 0.7,
|
224
|
borderWidth: 7
|
225
|
// color: '#a4edba',
|
226
|
// borderColor: 'gray'
|
227
|
}
|
228
|
},
|
229
|
data : mapCountryData as Highcharts.SeriesMapbubbleDataOptions,
|
230
|
dataLabels: {
|
231
|
enabled: true,
|
232
|
style: {
|
233
|
color: '#fff',
|
234
|
fontSize: '13px',
|
235
|
fontWeight: 'bold',
|
236
|
// textOutline: '1px #a1a1a1'
|
237
|
textOutline: '1px #000'
|
238
|
},
|
239
|
allowOverlap: true,
|
240
|
formatter: function() {
|
241
|
// return this.point.z.toFixed(1) + '%';
|
242
|
return this.point['z'].toLocaleString();
|
243
|
}
|
244
|
},
|
245
|
// minSize: 4,
|
246
|
// maxSize: '12%',
|
247
|
tooltip: {
|
248
|
headerFormat: '<span style="font-size: 120%; font-weight: bold; margin-bottom: 15px">{point.key}</span><br>',
|
249
|
// pointFormat: '{point.properties.name}: {point.z:.1f}%'
|
250
|
pointFormat: '{point.z} {series.name}',
|
251
|
}
|
252
|
} as Highcharts.SeriesMapbubbleOptions]
|
253
|
};
|
254
|
}
|
255
|
|
256
|
countrySelected(countryName: string) {
|
257
|
this.emitSelectedCountry.emit(countryName);
|
258
|
}
|
259
|
|
260
|
isEmbedRoute() {
|
261
|
return (this.router.url === '/overview-map-embed');
|
262
|
}
|
263
|
}
|