-
Notifications
You must be signed in to change notification settings - Fork 5
/
tracker.component.ts
80 lines (73 loc) · 1.94 KB
/
tracker.component.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
import { DateWiseData } from './../models/date-wise-data';
import { map } from 'rxjs/operators';
import { GlobalDataSummary } from './../models/global-dat';
import { DataServiceService } from './../services/data-service.service';
import { Component, OnInit } from '@angular/core';
import { merge } from 'rxjs';
@Component({
selector: 'app-tracker',
templateUrl: './tracker.component.html',
styleUrls: ['./tracker.component.css']
})
export class TrackerComponent implements OnInit {
data: GlobalDataSummary[] = [];
countries: string[] = [];
totalConfirmed = 0;
totalActive = 0;
totalDeaths = 0;
totalRecovered = 0;
selectedCountryData !: DateWiseData[];
dateWiseData: any;
loading = true;
options!: {
height: 500,
animation: {
duration: 1000,
easing: 'out',
},
}
constructor(private service: DataServiceService) { }
ngOnInit(): void {
merge(
this.service.getDateWiseData().pipe(
map(result => {
this.dateWiseData = result;
})
),
this.service.getGlobalData().pipe(map(result => {
this.data = result;
this.data.forEach(cs => {
this.countries.push(cs.country)
})
}))
).subscribe(
{
complete: () => {
this.updateValues('India')
this.loading = false;
}
}
)
}
updateChart(): void {
let dataTable = [];
dataTable.push(["Date", 'Cases'])
this.selectedCountryData.forEach(cs => {
dataTable.push([cs.date, cs.cases])
});
}
updateValues(country: string): void {
//console.log(country);
this.data.forEach(cs => {
if (cs.country === country) {
this.totalActive = cs.active
this.totalDeaths = cs.deaths
this.totalRecovered = cs.recovered
this.totalConfirmed = cs.confirmed
}
});
this.selectedCountryData = this.dateWiseData[country]
// console.log(this.selectedCountryData);
this.updateChart();
}
}