-
Notifications
You must be signed in to change notification settings - Fork 103
/
Copy pathaf-card.component.ts
152 lines (141 loc) · 4.28 KB
/
af-card.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
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
import { Component, OnInit, ViewChild, AfterViewInit } from '@angular/core';
import { ActivatedRoute, Router } from '@angular/router';
import { BaseChartDirective } from 'ng2-charts';
import { tap, map } from 'rxjs/operators';
import { DataFormService } from '@geonature_common/form/data-form.service';
import { AppConfig } from '@geonature_config/app.config';
import { CommonService } from '@geonature_common/service/common.service';
@Component({
selector: 'pnx-af-card',
templateUrl: './af-card.component.html',
styleUrls: ['./af-card.component.scss'],
})
export class AfCardComponent implements OnInit {
public id_af: number;
public af: any;
public stats: any;
public bbox: any;
public acquisitionFrameworks: any;
@ViewChild(BaseChartDirective, { static: false }) chart: BaseChartDirective;
// Type de graphe
public pieChartType = 'doughnut';
// Tableau contenant les labels du graphe
public pieChartLabels = [];
// Tableau contenant les données du graphe
public pieChartData = [];
// Tableau contenant les couleurs et la taille de bordure du graphe
public pieChartColors = [];
// Dictionnaire contenant les options à implémenter sur le graphe (calcul des pourcentages notamment)
public pieChartOptions = {
cutoutPercentage: 80,
legend: {
display: 'true',
position: 'left',
labels: {
fontSize: 15,
filter: function (legendItem, chartData) {
return chartData.datasets[0].data[legendItem.index] != 0;
},
},
},
plugins: {
labels: [
{
render: 'label',
arc: true,
fontSize: 14,
position: 'outside',
overlap: false,
},
{
render: 'percentage',
fontColor: 'white',
fontSize: 14,
fontStyle: 'bold',
precision: 2,
textShadow: true,
overlap: false,
},
],
},
};
public spinner = true;
public APP_CONFIG = AppConfig;
constructor(
private _dfs: DataFormService,
private _route: ActivatedRoute,
private _router: Router,
private _commonService: CommonService
) {}
ngOnInit() {
this._route.params.subscribe((params) => {
this.id_af = params['id'];
if (this.id_af) {
this.getAf();
this.getTaxaDistribution();
this.getStats();
this.getBbox();
}
});
}
getAf() {
this._dfs
.getAcquisitionFramework(this.id_af)
.pipe(
map((af) => {
if (af.acquisition_framework_start_date) {
af.acquisition_framework_start_date = new Date(
af.acquisition_framework_start_date
).toLocaleDateString();
}
if (af.acquisition_framework_end_date) {
af.acquisition_framework_end_date = new Date(
af.acquisition_framework_end_date
).toLocaleDateString();
}
return af;
})
)
.subscribe(
(af) => (this.af = af),
(err) => {
if (err.status === 404) {
this._commonService.translateToaster('error', 'MetaData.AF404');
}
this._router.navigate(['/metadata']);
}
);
}
getStats() {
this._dfs.getAcquisitionFrameworkStats(this.id_af).subscribe((res) => (this.stats = res));
}
getBbox() {
this._dfs.getAcquisitionFrameworkBbox(this.id_af).subscribe((res) => (this.bbox = res));
}
getTaxaDistribution() {
this.spinner = true;
this._dfs
.getTaxaDistribution('group2_inpn', { id_af: this.id_af })
.pipe(tap(() => (this.spinner = false)))
.subscribe((res) => {
this.pieChartData.length = 0;
this.pieChartLabels.length = 0;
this.pieChartData = [];
this.pieChartLabels = [];
for (let row of res) {
this.pieChartData.push(row['count']);
this.pieChartLabels.push(row['group']);
}
setTimeout(() => {
this.chart && this.chart.chart.update();
}, 1000);
});
}
getPdf() {
const url = `${AppConfig.API_ENDPOINT}/meta/acquisition_frameworks/export_pdf/${this.af.id_acquisition_framework}`;
const chart_img = this.chart ? this.chart.ctx['canvas'].toDataURL('image/png') : '';
this._dfs.uploadCanvas(chart_img).subscribe((data) => {
window.open(url);
});
}
}