Project

General

Profile

1
import { Component, OnInit } from '@angular/core';
2
import { printPage } from '../../shared/reusablecomponents/print-function';
3
import { DomSanitizer, SafeResourceUrl } from '@angular/platform-browser';
4
import { DataService } from '../../services/data.service';
5
import { DataHandlerService } from '../../services/data-handler.service';
6
import { CountryTableData, EuropeData } from '../../domain/overview-map-data';
7
import { environment } from '../../../environments/environment';
8
import { TreemapHighchartsData } from '../../domain/treemap-highcharts-data';
9
import { publicationPalette, datasetPalette, softwarePalette, otherResearchProductsPalette } from '../../chart-palettes';
10

    
11
@Component({
12
  selector: 'app-data-view',
13
  templateUrl: './data-view.component.html',
14
})
15

    
16
export class DataViewComponent implements OnInit {
17

    
18
  // @Input() type: string;
19
  // @Input() countries: CountryOverview[];
20

    
21
  private chartsURL = environment.API_ENDPOINT + 'chart?json=';
22
  private profileName = environment.profileName;
23

    
24
  private publicationPalette = publicationPalette;
25
  private datasetPalette = datasetPalette;
26
  private softwarePalette = softwarePalette;
27
  private otherResearchProductsPalette = otherResearchProductsPalette;
28

    
29
  activeView: string = 'absolute';
30
  contentAbsoluteSelection: string = 'affiliated';
31
  contentPercentageSelection: string = 'affiliated';
32

    
33
  tableAbsoluteData: CountryTableData[];
34
  tablePercentageData: CountryTableData[];
35

    
36
  loadingAbsoluteTable: boolean = true;
37
  loadingPercentageTable: boolean = true;
38

    
39
  europeOverviewData: EuropeData;
40

    
41
  oaNoaPublicationsTimelineURL: SafeResourceUrl;
42
  oaNoaDatasetsTimelineURL: SafeResourceUrl;
43
  oaNoaSoftwareTimelineURL: SafeResourceUrl;
44
  oaNoaOtherTimelineURL: SafeResourceUrl;
45

    
46
  fundersResultsData: TreemapHighchartsData[];
47

    
48
  constructor(private sanitizer: DomSanitizer,
49
              private dataService: DataService,
50
              private dataHandlerService: DataHandlerService) {}
51

    
52
  ngOnInit(): void {
53
    this.getAbsoluteData();
54
    this.getPercentageData();
55
    this.getEuropeOverviewData();
56
    this.getFundersResults();
57
  }
58

    
59
  getAbsoluteData() {
60
    this.loadingAbsoluteTable = true;
61
    this.dataService.getOverviewTableAbsoluteData(this.contentAbsoluteSelection).subscribe(
62
      rawData => {
63
        this.tableAbsoluteData = this.dataHandlerService.convertRawDataToAbsoluteTableData(rawData);
64
        this.loadingAbsoluteTable = false;
65
      }, error => {
66
        console.log(error);
67
        this.loadingAbsoluteTable = false;
68
      }
69
    );
70
  }
71

    
72
  getPercentageData() {
73
    this.loadingPercentageTable = true;
74
    this.dataService.getOverviewTablePercentageData(this.contentPercentageSelection).subscribe(
75
      rawData => {
76
        this.tablePercentageData = this.dataHandlerService.convertRawDataToPercentageTableData(rawData);
77
        this.loadingPercentageTable = false;
78
      }, error => {
79
        console.log(error);
80
        this.loadingPercentageTable = false;
81
      }
82
    );
83
  }
84

    
85
  getEuropeOverviewData() {
86
    this.dataService.getEuropeOAPercentages().subscribe(
87
      rawData => {
88
        this.europeOverviewData = this.dataHandlerService.convertRawDataToEuropeOverviewData(rawData);
89
      }, error => {
90
        console.log(error);
91
      }
92
    );
93
  }
94

    
95
  getFundersResults() {
96
    this.dataService.getFundersResults().subscribe(
97
      rawData => {
98
        this.fundersResultsData = this.dataHandlerService.convertRawDataToTreemapHighchartsData(rawData);
99
      }, error => {
100
        console.log(error);
101
      }
102
    );
103
  }
104

    
105
  getContentAbsolute(contentSelection: string): void {
106
    this.contentAbsoluteSelection = contentSelection;
107
    this.getAbsoluteData();
108
  }
109

    
110
  getContentPercentage(contentSelection: string): void {
111
    this.contentPercentageSelection = contentSelection;
112
    this.getPercentageData();
113
  }
114

    
115
  changeView(view: string) {
116
    this.activeView = view;
117
    if (view === 'graph') {
118

    
119
      if (!this.oaNoaPublicationsTimelineURL) {
120
        this.oaNoaPublicationsTimelineURL = this.sanitizer.bypassSecurityTrustResourceUrl(this.chartsURL + encodeURIComponent(`{"library":"HighCharts","chartDescription":{"queries":[{"name":"OA","type":"column","query":{"name":"new.oso.result_timeline.results.oa","parameters":["publication"],"profile":"${this.profileName}"}},{"name":"Non-OA","type":"column","query":{"name":"new.oso.result_timeline.results.non_oa","parameters":["publication"],"profile":"${this.profileName}"}}],"chart":{"backgroundColor":"#FFFFFFFF","borderColor":"#335cadff","borderRadius":0,"borderWidth":0,"plotBorderColor":"#ccccccff","plotBorderWidth":0},"title":{"text":"Publications","align":"left","margin":50},"subtitle":{},"yAxis":{"title":{"text":""}},"xAxis":{"title":{"text":""}},"lang":{"noData":"No Data available for the Query"},"exporting":{"enabled":true},"plotOptions":{"series":{"dataLabels":{"enabled":false},"stacking":"normal"}},"legend":{"enabled":true,"align":"center","verticalAlign":"bottom","layout":"horizontal"},"credits":{"href":null,"enabled":false},"colors":[\"${this.publicationPalette.join('","')}\"]}}`));
121
      }
122
      if (!this.oaNoaDatasetsTimelineURL) {
123
        this.oaNoaDatasetsTimelineURL = this.sanitizer.bypassSecurityTrustResourceUrl(this.chartsURL + encodeURIComponent(`{"library":"HighCharts","chartDescription":{"queries":[{"name":"OA","type":"column","query":{"name":"new.oso.result_timeline.results.oa","parameters":["dataset"],"profile":"${this.profileName}"}},{"name":"Non-OA","type":"column","query":{"name":"new.oso.result_timeline.results.non_oa","parameters":["dataset"],"profile":"${this.profileName}"}}],"chart":{"backgroundColor":"#FFFFFFFF","borderColor":"#335cadff","borderRadius":0,"borderWidth":0,"plotBorderColor":"#ccccccff","plotBorderWidth":0},"title":{"text":"Datasets","align":"left","margin":50},"subtitle":{},"yAxis":{"title":{"text":""}},"xAxis":{"title":{"text":""}},"lang":{"noData":"No Data available for the Query"},"exporting":{"enabled":true},"plotOptions":{"series":{"dataLabels":{"enabled":false},"stacking":"normal"}},"legend":{"enabled":true,"align":"center","verticalAlign":"bottom","layout":"horizontal"},"credits":{"href":null,"enabled":false},"colors":[\"${this.datasetPalette.join('","')}\"]}}`));
124
      }
125
      if (!this.oaNoaSoftwareTimelineURL) {
126
        this.oaNoaSoftwareTimelineURL = this.sanitizer.bypassSecurityTrustResourceUrl(this.chartsURL + encodeURIComponent(`{"library":"HighCharts","chartDescription":{"queries":[{"name":"OA","type":"column","query":{"name":"new.oso.result_timeline.results.oa","parameters":["software"],"profile":"${this.profileName}"}},{"name":"Non-OA","type":"column","query":{"name":"new.oso.result_timeline.results.non_oa","parameters":["software"],"profile":"${this.profileName}"}}],"chart":{"backgroundColor":"#FFFFFFFF","borderColor":"#335cadff","borderRadius":0,"borderWidth":0,"plotBorderColor":"#ccccccff","plotBorderWidth":0},"title":{"text":"Software","align":"left","margin":50},"subtitle":{},"yAxis":{"title":{"text":""}},"xAxis":{"title":{"text":""}},"lang":{"noData":"No Data available for the Query"},"exporting":{"enabled":true},"plotOptions":{"series":{"dataLabels":{"enabled":false},"stacking":"normal"}},"legend":{"enabled":true,"align":"center","verticalAlign":"bottom","layout":"horizontal"},"credits":{"href":null,"enabled":false},"colors":[\"${this.softwarePalette.join('","')}\"]}}`));
127
      }
128
      if (!this.oaNoaOtherTimelineURL) {
129
        this.oaNoaOtherTimelineURL = this.sanitizer.bypassSecurityTrustResourceUrl(this.chartsURL + encodeURIComponent(`{"library":"HighCharts","chartDescription":{"queries":[{"name":"OA Other Research Products","type":"column","query":{"name":"new.oso.result_timeline.results.oa","parameters":["other"],"profile":"${this.profileName}"}},{"name":"Non-OA Other Research Products","type":"column","query":{"name":"new.oso.result_timeline.results.non_oa","parameters":["other"],"profile":"${this.profileName}"}}],"chart":{"backgroundColor":"#FFFFFFFF","borderColor":"#335cadff","borderRadius":0,"borderWidth":0,"plotBorderColor":"#ccccccff","plotBorderWidth":0},"title":{"text":"Other Research Products","align":"left","margin":50},"subtitle":{},"yAxis":{"title":{"text":""}},"xAxis":{"title":{"text":""}},"lang":{"noData":"No Data available for the Query"},"exporting":{"enabled":true},"plotOptions":{"series":{"dataLabels":{"enabled":false},"stacking":"normal"}},"legend":{"enabled":true,"align":"center","verticalAlign":"bottom","layout":"horizontal"},"credits":{"href":null,"enabled":false},"colors":[\"${this.otherResearchProductsPalette.join('","')}\"]}}`));
130
      }
131
    }
132
  }
133

    
134
  printOverviewData(sectionID: string) {
135
    printPage(sectionID);
136
  }
137
}
(6-6/12)