ptut-vhost/webpack/data/home.js

78 lines
2.8 KiB
JavaScript

/* (1) Load statistics
---------------------------------------------------------*/
/* (1) Initialize list */
gstore.add('stats', null);
gstore.add('dimensions', null);
/* (2) Get statistics */
api.call('GET department/stats', {}, function(rs) {
// {1} If error -> abort //
if (rs.error !== 0) {
return console.log('No formation found, error: ' + rs.error);
}
let maxValue = null; // plus haute valeur des stats
let maxLabelLength = null; // plus longues chaîne de caractères pour les stats
let data = {}; // ensemble des statistiques à transmettre à VueJS
let map = {
"potentiel" : "Heures potentielles",
"sous_service" : "Heures en sous-services",
"heures_comp" : "Heures comp.",
"heures_vacataire" : "Heures vacataires",
"heures_exterieur" : "Heures à l'extérieurs",
"heures_ue_desactive" : "Heures UE annulées",
"nbr_ue_desactive" : "Nombre d'UE annulées"
};
for (let stat in rs.data) {
// détection de la plus grande valeur statistique
maxValue = rs.data[stat] > maxValue ? rs.data[stat] : maxValue;
// détection du plus grand nom présent
maxLabelLength = map[stat].length > maxLabelLength ? map[stat].length : maxLabelLength;
data[map[stat]] = Math.round(rs.data[stat] * 100) / 100;
}
// légendes à afficher en plus de la valeur
gstore.get.titles = {};
gstore.get.titles[map['heures_ue_desactive']] = `sur ${data[map['nbr_ue_desactive']]} UE annulées`;
// statistiques à ne pas afficher
delete data[map['nbr_ue_desactive']];
gstore.get.stats = data;
gstore.get.dimensions = {
padding: 5,
text: {
size: maxLabelLength * 8.5,
alignH: 5,
alignV: 20,
},
bin: {
count: Object.keys(gstore.get.stats).length,
width: 30,
spacing: 15,
margin: 5
}
};
if (maxValue != null) {
let magnitude = Math.pow(10, maxValue.length-1)/2; // ordre de grandeur du nombre
maxValue = Math.round(
((gstore.get.dimensions.bin.margin/100)+1) // on rajoute la marge afin qu'un "bin" ne dépasse jamais sur la droite
* maxValue / magnitude ) * magnitude;
}
gstore.get.maxValue = maxValue;
gstore.get.dimensions.axis = {
height: (gstore.get.dimensions.bin.count*gstore.get.dimensions.bin.width) + ((gstore.get.dimensions.bin.count)*gstore.get.dimensions.bin.spacing),
width: 500,
precision: 4
};
gstore.get.viewBox = `0 0 ${gstore.get.dimensions.axis.width + gstore.get.dimensions.text.size + 50} ${gstore.get.dimensions.axis.height + 30}`;
});
gstore.add('colors', ["blue", "yellow", "green", "red", "purple", "lightblue", "lightred", "lightyellow", "lightgreen", "lightpurple"]);