271 lines
8.7 KiB
TypeScript
271 lines
8.7 KiB
TypeScript
import { Injectable } from '@angular/core';
|
|
import { Configuration } from 'ng-chartist';
|
|
|
|
import { BarConfig, DoughnutConfig, LineConfig } from 'src/app/core/models';
|
|
|
|
@Injectable({ providedIn: 'root' })
|
|
export class UtilitiesService {
|
|
private _coeffKgLbs: number = 2.20462;
|
|
private _coeffFtM: number = 0.092903;
|
|
|
|
constructor() { }
|
|
|
|
getCoeffKgLbs(): number {
|
|
return this._coeffKgLbs;
|
|
}
|
|
|
|
getCoeffFtM(): number {
|
|
return this._coeffFtM;
|
|
}
|
|
|
|
getBarConfig(): Configuration {
|
|
let config: Configuration = {
|
|
type: 'Bar',
|
|
data: {
|
|
"labels": [],
|
|
"series": []
|
|
},
|
|
options: {},
|
|
responsiveOptions: []
|
|
};
|
|
return config;
|
|
}
|
|
|
|
getChartColors(): string[] {
|
|
let colors: string[] = [
|
|
'ct-color-a',
|
|
'ct-color-b',
|
|
'ct-color-c',
|
|
'ct-color-d',
|
|
'ct-color-e',
|
|
'ct-color-f',
|
|
'ct-color-g',
|
|
'ct-color-h',
|
|
'ct-color-i',
|
|
'ct-color-j',
|
|
'ct-color-k',
|
|
'ct-color-l',
|
|
'ct-color-m',
|
|
'ct-color-n',
|
|
'ct-color-o',
|
|
'ct-color-p',
|
|
'ct-color-q',
|
|
'ct-color-r'
|
|
];
|
|
return colors;
|
|
}
|
|
|
|
getCurrentDateFr(): string {
|
|
return new Date().toLocaleDateString("fr");
|
|
}
|
|
|
|
getSeriesColors(opacity: number, palette: string = 'all'): string[] {
|
|
let colors: string[] = [];
|
|
switch (palette) {
|
|
case 'red':
|
|
colors = [
|
|
`rgba(163, 0, 0, ${opacity})`,
|
|
`rgba(178, 47, 25, ${opacity})`,
|
|
`rgba(192, 74, 49, ${opacity})`,
|
|
`rgba(205, 99, 72, ${opacity})`,
|
|
`rgba(217, 122, 97, ${opacity})`,
|
|
`rgba(228, 145, 122, ${opacity})`,
|
|
`rgba(238, 168, 148, ${opacity})`,
|
|
`rgba(247, 192, 175, ${opacity})`,
|
|
`rgba(255, 215, 203, ${opacity})`
|
|
];
|
|
break;
|
|
case 'green':
|
|
colors = [
|
|
`rgba(0, 109, 45, ${opacity})`,
|
|
`rgba(42, 124, 64, ${opacity})`,
|
|
`rgba(67, 140, 83, ${opacity})`,
|
|
`rgba(90, 155, 102, ${opacity})`,
|
|
`rgba(112, 171, 122, ${opacity})`,
|
|
`rgba(134, 187, 142, ${opacity})`,
|
|
`rgba(156, 203, 163, ${opacity})`,
|
|
`rgba(179, 219, 184, ${opacity})`,
|
|
`rgba(201, 235, 205, ${opacity})`
|
|
];
|
|
break;
|
|
case 'blue':
|
|
colors = [
|
|
`rgba(0, 76, 109, ${opacity})`,
|
|
`rgba(37, 94, 126, ${opacity})`,
|
|
`rgba(61, 112, 143, ${opacity})`,
|
|
`rgba(83, 131, 161, ${opacity})`,
|
|
`rgba(105, 150, 179, ${opacity})`,
|
|
`rgba(127, 170, 198, ${opacity})`,
|
|
`rgba(148, 190, 217, ${opacity})`,
|
|
`rgba(171, 210, 236, ${opacity})`,
|
|
`rgba(193, 231, 255, ${opacity})`
|
|
];
|
|
break;
|
|
case 'all':
|
|
default:
|
|
colors = [
|
|
`rgba(32, 182, 252, ${opacity})`,
|
|
`rgba(241, 80, 80, ${opacity})`,
|
|
`rgba(2, 191, 171, ${opacity})`,
|
|
`rgba(255, 153, 0, ${opacity})`,
|
|
`rgba(101, 218, 224, ${opacity})`,
|
|
`rgba(138, 101, 224, ${opacity})`,
|
|
`rgba(0, 137, 123, ${opacity})`,
|
|
`rgba(181, 17, 86, ${opacity})`,
|
|
`rgba(93, 204, 137, ${opacity})`,
|
|
`rgba(255, 226, 5, ${opacity})`,
|
|
`rgba(191, 101, 224, ${opacity})`,
|
|
`rgba(76, 174, 76, ${opacity})`,
|
|
`rgba(51, 122, 183, ${opacity})`,
|
|
`rgba(237, 80, 148, ${opacity})`,
|
|
`rgba(253, 24, 243, ${opacity})`,
|
|
`rgba(214, 31, 31, ${opacity})`,
|
|
`rgba(153, 171, 180, ${opacity})`,
|
|
`rgba(205, 186, 152, ${opacity})`,
|
|
`rgba(101, 224, 184, ${opacity})`,
|
|
`rgba(2, 191, 171, ${opacity})`,
|
|
`rgba(101, 218, 224, ${opacity})`,
|
|
`rgba(161, 199, 161, ${opacity})`,
|
|
`rgba(217, 202, 174, ${opacity})`,
|
|
`rgba(151, 136, 199, ${opacity})`,
|
|
`rgba(212, 206, 112, ${opacity})`,
|
|
`rgba(255, 255, 255, ${opacity})`
|
|
];
|
|
break;
|
|
}
|
|
return colors;
|
|
}
|
|
|
|
getDoughnutChartConfig(): DoughnutConfig {
|
|
let config: DoughnutConfig = {
|
|
doughnutChartLabels: [],
|
|
doughnutChartDatasets: [
|
|
{
|
|
data: [],
|
|
label: 'Nombre total de sauts',
|
|
backgroundColor: this.getSeriesColors(0.8),
|
|
borderColor: this.getSeriesColors(1), // 'rgba(255, 255, 255, 1)'
|
|
borderWidth: 2
|
|
}
|
|
],
|
|
doughnutChartOptions: {
|
|
elements: {
|
|
arc: {
|
|
borderWidth: 2,
|
|
}
|
|
},
|
|
plugins: {
|
|
legend: {
|
|
display: true,
|
|
position: 'left'
|
|
}
|
|
},
|
|
responsive: true
|
|
},
|
|
doughnutChartLegend: false
|
|
};
|
|
return config;
|
|
}
|
|
|
|
getBarChartConfig(): BarConfig {
|
|
let config: BarConfig = {
|
|
barChartData: {
|
|
labels: [''],
|
|
datasets: []
|
|
},
|
|
barChartOptions: {
|
|
elements: {
|
|
bar: {
|
|
borderWidth: 1,
|
|
}
|
|
},
|
|
responsive: true
|
|
},
|
|
barChartPlugins: [],
|
|
barChartLegend: false
|
|
};
|
|
return config;
|
|
}
|
|
|
|
getHorizontalBarChartConfig(): BarConfig {
|
|
let config: BarConfig = {
|
|
barChartData: {
|
|
labels: [''],
|
|
datasets: []
|
|
},
|
|
barChartOptions: {
|
|
indexAxis: 'y',
|
|
elements: {
|
|
bar: {
|
|
borderWidth: 1,
|
|
}
|
|
},
|
|
plugins: {
|
|
legend: {
|
|
display: true,
|
|
position: 'left'
|
|
},
|
|
title: {
|
|
display: false,
|
|
text: 'Nombre total de sauts'
|
|
}
|
|
},
|
|
responsive: true,
|
|
aspectRatio: 3,
|
|
scales: {
|
|
x: {
|
|
beginAtZero: true,
|
|
ticks: { color: 'rgba(255,255,255,0.3)' },
|
|
grid: { color: 'rgba(255,255,255,0.2)', display: true, tickBorderDash: [1,2] }
|
|
},
|
|
y: {
|
|
beginAtZero: true,
|
|
ticks: { color: 'rgba(255,255,255,0.3)' },
|
|
grid: { color: 'rgba(255,255,255,0.3)', display: false }
|
|
}
|
|
}
|
|
},
|
|
barChartPlugins: [],
|
|
barChartLegend: false
|
|
};
|
|
return config;
|
|
}
|
|
|
|
getLineChartConfig(): LineConfig {
|
|
let config: LineConfig = {
|
|
lineChartData: {
|
|
labels: [],
|
|
datasets: []
|
|
},
|
|
lineChartOptions: {
|
|
plugins: {
|
|
legend: {
|
|
display: true,
|
|
position: 'bottom'
|
|
}
|
|
},
|
|
interaction: {
|
|
intersect: false,
|
|
axis: 'x'
|
|
},
|
|
scales: {
|
|
x: {
|
|
display: false,
|
|
},
|
|
y: {
|
|
display: true,
|
|
min: 60,
|
|
max: 200,
|
|
ticks: { color: 'rgba(255,255,255,0.3)' },
|
|
grid: { color: 'rgba(255,255,255,0.3)', display: true }
|
|
}
|
|
},
|
|
responsive: true,
|
|
maintainAspectRatio: true
|
|
},
|
|
lineChartLegend: true
|
|
};
|
|
return config;
|
|
}
|
|
}
|