/* (1) Load statistics ---------------------------------------------------------*/ /* (1) Initialize list */ gstore.add('stats', []); 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; let maxLabelLength = null; let data = {}; 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) { maxValue = rs.data[stat] > maxValue ? rs.data[stat] : maxValue; maxLabelLength = map[stat].length > maxLabelLength ? map[stat].length : maxLabelLength; data[map[stat]] = Math.round(rs.data[stat] * 100) / 100; } gstore.get.titles = {}; gstore.get.titles[map['heures_ue_desactive']] = `sur ${data[map['nbr_ue_desactive']]} UE annulées`; delete data[map['nbr_ue_desactive']]; gstore.get.stats = data; gstore.get.dimensions = { padding: 5, text: { size: maxLabelLength * 9.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.add('colors', ["blue", "yellow", "green", "red", "purple", "lightblue", "lightred", "lightyellow", "lightgreen", "lightpurple"]);