Project

General

Profile

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