Project

General

Profile

1
import { Component, OnInit } from '@angular/core';
2
import { ActivatedRoute } from '@angular/router';
3
import { DomSanitizer } from '@angular/platform-browser';
4
import { DataService } from '../../services/data.service';
5
import { DataHandlerService } from '../../services/data-handler.service';
6
import { CountryOverviewData, EuropeData, SelectedCountry } from '../../domain/overview-map-data';
7
import { MatSlideToggleChange } from '@angular/material/slide-toggle';
8

    
9
@Component({
10
  selector: 'app-continent',
11
  templateUrl: './continent.component.html',
12
})
13

    
14
export class ContinentComponent implements OnInit {
15

    
16
  lastUpdateDate: string;
17

    
18
  continentName: string;
19

    
20
  europeOverviewData: EuropeData;
21
  europeOverviewMapData: EuropeData;
22

    
23
  mapViewActive = false;
24
  selectedCountry: SelectedCountry = null;
25
  selectedCountryData: CountryOverviewData = null;
26

    
27
  constructor(private dataService: DataService,
28
              private dataHandlerService: DataHandlerService,
29
              private route: ActivatedRoute,
30
              private sanitizer: DomSanitizer) { }
31

    
32
  ngOnInit(): void {
33

    
34
    // window.scroll(0, 0);
35

    
36
    // this.continentName = this.route.snapshot.paramMap.get('continentName');
37
    this.continentName = 'europe';
38

    
39
    console.log('continentName: ', this.continentName);
40

    
41
    this.dataService.getLastUpdateDate().subscribe(
42
      rawData => {
43
        this.lastUpdateDate = this.dataHandlerService.convertRawDataToLastUpdateDate(rawData);
44
      }, error => {
45
        console.log(error);
46
      }
47
    );
48

    
49
    this.dataService.getEuropeOAPercentages().subscribe(
50
      rawData => {
51
        this.europeOverviewData = this.dataHandlerService.convertRawDataToEuropeOverviewData(rawData);
52
      }, error => {
53
        console.log(error);
54
      }
55
    );
56

    
57
    this.dataService.getEuropeOverviewData().subscribe(
58
      rawData => {
59
        this.europeOverviewMapData = this.dataHandlerService.convertRawDataToEuropeOverviewData(rawData);
60
      }, error => {
61
        console.log(error);
62
      }
63
    );
64

    
65
    // this.createOverviewContent();
66
  }
67

    
68
  getHeight(percentage: number) {
69
    if (percentage < 50) {
70
      return Math.round(percentage) * 1.5;
71
    } else {
72
      return Math.round(percentage);
73
    }
74
  }
75

    
76
  getNumberFontSize(percentage: number) {
77
    if (percentage < 50) {
78
      return Math.round(percentage * 45 / 100) * 1.5;
79
    } else {
80
      return Math.round(percentage * 45 / 100);
81
    }
82
  }
83

    
84
  getEntityNameFontSize(percentage: number) {
85
    if (percentage < 50) {
86
      return Math.round(percentage * 30 / 100) * 1.5;
87
    } else {
88
      return Math.round(percentage * 30 / 100);
89
    }
90
  }
91

    
92
  getPublicationsIconWidth(percentage: number) {
93
    if (percentage < 50) {
94
      return Math.round(percentage * 60 / 100) * 1.5;
95
    } else {
96
      return Math.round(percentage * 60 / 100);
97
    }
98
  }
99

    
100
  getDatasetsIconWidth(percentage: number) {
101
    if (percentage < 50) {
102
      return Math.round(percentage * 45 / 100) * 1.5;
103
    } else {
104
      return Math.round(percentage * 45 / 100);
105
    }
106
  }
107

    
108
  getSoftwareIconWidth(percentage: number) {
109
    if (percentage < 50) {
110
      return Math.round(percentage * 50 / 100) * 1.5;
111
    } else {
112
      return Math.round(percentage * 50 / 100);
113
    }
114
  }
115

    
116
  getOtherIconWidth(percentage: number) {
117
    if (percentage < 50) {
118
      return Math.round(percentage * 45 / 100) * 1.5;
119
    } else {
120
      return Math.round(percentage * 45 / 100);
121
    }
122
  }
123

    
124
  /** Europe Map  --> **/
125
  // toggleView(show: string) {
126
  //   if (show === 'map') {
127
  //     this.mapViewActive = true;
128
  //   } else if (show === 'columns') {
129
  //     this.mapViewActive = false;
130
  //   }
131
  // }
132

    
133
  toggleView(ob: MatSlideToggleChange) {
134
    if (ob.checked) {
135
      this.mapViewActive = true;
136
    } else {
137
      this.mapViewActive = false;
138
    }
139
  }
140

    
141
  countrySelected(selectedCountry: SelectedCountry) {
142
    this.selectedCountry = selectedCountry;
143
    this.selectedCountryData = null;
144
    this.dataService.getCountryOverviewData(this.selectedCountry.code).subscribe(
145
      rawData => {
146
        this.selectedCountryData = this.dataHandlerService.convertRawDataToCountryOverviewData(rawData);
147
      }, error => {
148
        console.log(error);
149
      }
150
    );
151
  }
152

    
153
  deselectCountry() {
154
    this.selectedCountry = null;
155
    this.selectedCountryData = null;
156
  }
157
  /** <-- Europe Map **/
158

    
159
}
(3-3/4)