2016-05-24 07:01:16 +00:00
|
|
|
var subPhone = $('section[data-sublink="phone"]');
|
|
|
|
subPhone.style.display = 'flex';
|
|
|
|
subPhone.style.flexWrap = 'wrap';
|
|
|
|
subPhone.style.justifyContent = 'space-around';
|
|
|
|
|
2016-05-25 12:50:29 +00:00
|
|
|
|
2016-05-24 07:01:16 +00:00
|
|
|
/* [0] Paramètres globaux
|
2016-04-19 15:08:59 +00:00
|
|
|
=========================================================*/
|
2016-05-24 07:01:16 +00:00
|
|
|
subject = 273;
|
|
|
|
|
2016-05-26 09:47:02 +00:00
|
|
|
var charts = ['sexe', 'direction', 'type', 'ages', 'relations', 'weekdays', 'duration', 'timeofday'];
|
2016-05-24 07:01:16 +00:00
|
|
|
var canvas = []; // Contiendra les canvas
|
|
|
|
var instances = []; // Contiendra les charts
|
|
|
|
|
2016-05-26 09:47:02 +00:00
|
|
|
Highcharts.dateFormats = {
|
|
|
|
X: function (timestamp) {
|
|
|
|
var d = new Date(timestamp*1000);
|
|
|
|
return d.toLocaleTimeString();
|
|
|
|
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2016-05-25 12:50:29 +00:00
|
|
|
|
|
|
|
/* [1] Gestion des options par défaut
|
|
|
|
=========================================================*/
|
|
|
|
var plotOptions = {};
|
|
|
|
|
|
|
|
/* (1) Pour les graphiques de type 'pie' */
|
|
|
|
plotOptions['pie'] = { pie: { // pie
|
2016-05-25 10:39:46 +00:00
|
|
|
showInLegend: true,
|
2016-05-25 08:09:30 +00:00
|
|
|
innerSize: '50%',
|
|
|
|
allowPointSelect: true,
|
|
|
|
cursor: 'pointer',
|
|
|
|
startAngle: -90,
|
|
|
|
endAngle: 90,
|
|
|
|
dataLabels: {
|
2016-05-25 10:39:46 +00:00
|
|
|
enabled: false,
|
2016-05-25 10:30:31 +00:00
|
|
|
distance: 10,
|
2016-05-25 08:09:30 +00:00
|
|
|
format: '<b>{point.name}</b>: {point.percentage:.1f} %',
|
2016-05-25 10:30:31 +00:00
|
|
|
style: { color: 'black', textShadow: '0 0 2px white' }
|
2016-05-25 08:09:30 +00:00
|
|
|
}
|
2016-05-25 12:50:29 +00:00
|
|
|
} };
|
|
|
|
|
2016-05-26 09:47:02 +00:00
|
|
|
/* (2) Pour les graphiques de type 'column' */
|
2016-05-25 15:27:18 +00:00
|
|
|
plotOptions['column'] = { column: { shadow: false, borderWidth: 0, stacking: null } };
|
2016-05-25 08:09:30 +00:00
|
|
|
|
2016-05-25 12:50:29 +00:00
|
|
|
/* (3) Pour le graphique des jours de la semaine */
|
2016-05-25 15:27:18 +00:00
|
|
|
plotOptions['weekdays'] = { column: { shadow: false, borderWidth: 0, stacking: 'normal', dataLabels: { enabled: true } } };
|
2016-05-25 08:09:30 +00:00
|
|
|
|
2016-05-26 09:47:02 +00:00
|
|
|
/* (4) Pour les graphiques de type 'bar' */
|
2016-05-25 15:27:18 +00:00
|
|
|
plotOptions['bar'] = { bar: { allowPointSelect: true, cursor: 'pointer' } };
|
2016-05-25 08:09:30 +00:00
|
|
|
|
2016-05-26 09:47:02 +00:00
|
|
|
/* (5) Pour les graphiques de type 'spline' */
|
|
|
|
plotOptions['spline'] = { spline: { pointInterval: 1000 } }; // 1 min
|
2016-05-25 10:30:31 +00:00
|
|
|
|
2016-05-25 08:09:30 +00:00
|
|
|
|
2016-05-25 12:50:29 +00:00
|
|
|
/* [2] On crée les conteneurs
|
2016-05-24 07:01:16 +00:00
|
|
|
=========================================================*/
|
|
|
|
for( var c in charts ){
|
2016-05-24 16:59:19 +00:00
|
|
|
canvas[c] = document.createElement('div');
|
2016-05-24 07:01:16 +00:00
|
|
|
canvas[c].id = charts[c];
|
2016-05-25 12:50:29 +00:00
|
|
|
canvas[c].style.width = canvas[c].style.height = '30em';
|
2016-05-24 16:59:19 +00:00
|
|
|
canvas[c].style.margin = '2em';
|
2016-05-24 07:01:16 +00:00
|
|
|
subPhone.appendChild( canvas[c] );
|
|
|
|
}
|
2016-04-19 15:08:59 +00:00
|
|
|
|
|
|
|
|
2016-05-25 12:50:29 +00:00
|
|
|
/* [3] Pour chaque graphique, on récupère les données et on les affiche
|
2016-04-15 10:10:38 +00:00
|
|
|
=========================================================*/
|
2016-05-24 07:01:16 +00:00
|
|
|
for( var c = 0 ; c < charts.length ; c++ ){
|
|
|
|
|
|
|
|
|
|
|
|
/* (1) On rédige la requête */
|
|
|
|
var request = {
|
|
|
|
path: 'chart/'+charts[c],
|
|
|
|
subject: subject
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
/* (2) On lance la requête */
|
|
|
|
api.send(request, function(response, args){
|
|
|
|
console.log(api.buffer);
|
|
|
|
// On récupère @c dans le scope du handler
|
|
|
|
var c = args[0];
|
|
|
|
|
|
|
|
/* (3) Si erreur, on quitte */
|
|
|
|
if( response.ModuleError != 0 )
|
|
|
|
return false;
|
|
|
|
|
2016-05-25 12:50:29 +00:00
|
|
|
/* [4] On construit les données
|
2016-05-24 07:01:16 +00:00
|
|
|
=========================================================*/
|
|
|
|
var data = {
|
|
|
|
labels: response.labels,
|
|
|
|
datasets: response.datasets
|
|
|
|
};
|
2016-04-15 16:40:15 +00:00
|
|
|
|
2016-05-25 12:50:29 +00:00
|
|
|
|
|
|
|
|
|
|
|
/* [5] On construit les options du graphique
|
2016-05-24 07:01:16 +00:00
|
|
|
=========================================================*/
|
2016-05-24 16:59:19 +00:00
|
|
|
/* (1) On définit les options */
|
|
|
|
var options = {
|
2016-05-25 12:50:29 +00:00
|
|
|
chart: { renderTo: canvas[c], type: response.type },
|
2016-05-24 16:59:19 +00:00
|
|
|
series: response.series,
|
2016-05-25 15:27:18 +00:00
|
|
|
xAxis: {},
|
|
|
|
yAxis: {},
|
|
|
|
tooltip: {}
|
|
|
|
|
2016-05-24 16:59:19 +00:00
|
|
|
};
|
2016-05-25 15:27:18 +00:00
|
|
|
// Si c'est un 'donut', on met plus petit
|
|
|
|
if( response.type == 'pie' )
|
|
|
|
canvas[c].style.width = canvas[c].style.height = '20em';
|
|
|
|
else
|
|
|
|
options.tooltip.headerFormat = '<b>{point.x}</b><br>';
|
2016-05-24 16:59:19 +00:00
|
|
|
|
2016-05-25 12:50:29 +00:00
|
|
|
// Gestion des options
|
2016-05-26 09:47:02 +00:00
|
|
|
if( plotOptions[charts[c]] != null )
|
2016-05-25 12:50:29 +00:00
|
|
|
options.plotOptions = plotOptions[charts[c]];
|
2016-05-26 09:47:02 +00:00
|
|
|
else if( plotOptions[response.type] != null )
|
2016-05-25 12:50:29 +00:00
|
|
|
options.plotOptions = plotOptions[response.type];
|
2016-05-26 09:47:02 +00:00
|
|
|
|
2016-05-25 12:50:29 +00:00
|
|
|
|
2016-05-25 10:30:31 +00:00
|
|
|
// types de données
|
2016-05-26 09:47:02 +00:00
|
|
|
if( response.xaxis != null ) options.xAxis = response.xaxis;
|
|
|
|
if( response.yaxis != null ) options.yAxis = response.yaxis;
|
2016-05-25 10:30:31 +00:00
|
|
|
|
2016-05-24 16:59:19 +00:00
|
|
|
// labels
|
2016-05-25 10:30:31 +00:00
|
|
|
if( response.xlabels != null ) options.xAxis.categories = response.xlabels;
|
|
|
|
if( response.ylabels != null ) options.yAxis.categories = response.ylabels;
|
2016-05-24 16:59:19 +00:00
|
|
|
|
2016-05-25 10:30:31 +00:00
|
|
|
// zoom
|
2016-05-26 09:47:02 +00:00
|
|
|
if( response.zoom != null ) options.chart.zoomType = response.zoom;
|
2016-05-24 16:59:19 +00:00
|
|
|
|
|
|
|
// titre
|
2016-05-26 09:47:02 +00:00
|
|
|
if( response.title != null ) options.title = { text: response.title };
|
2016-05-24 16:59:19 +00:00
|
|
|
|
2016-05-25 15:27:18 +00:00
|
|
|
// titres des axes
|
2016-05-26 09:47:02 +00:00
|
|
|
if( response.xtitle != null ) options.xAxis.title = { text: response.xtitle };
|
|
|
|
if( response.ytitle != null ) options.yAxis.title = { text: response.ytitle };
|
2016-05-25 15:27:18 +00:00
|
|
|
|
2016-05-24 16:59:19 +00:00
|
|
|
// pointFormat
|
2016-05-25 15:27:18 +00:00
|
|
|
if( response.pointFormat != null ) options.tooltip.pointFormat = response.pointFormat;
|
2016-05-24 16:59:19 +00:00
|
|
|
|
2016-05-25 15:27:18 +00:00
|
|
|
// headerFormat
|
|
|
|
if( response.headerFormat != null ) options.tooltip.headerFormat = response.headerFormat;
|
2016-05-25 12:50:29 +00:00
|
|
|
|
2016-05-26 09:47:02 +00:00
|
|
|
|
2016-05-25 12:50:29 +00:00
|
|
|
/* [6] On crée le graphique
|
|
|
|
=========================================================*/
|
2016-05-24 16:59:19 +00:00
|
|
|
instances[c] = new Highcharts.Chart(options);
|
|
|
|
|
2016-04-15 16:40:15 +00:00
|
|
|
|
2016-05-25 12:50:29 +00:00
|
|
|
}, null, c); // On passe @c au @handler pour l'avoir dans le scope
|
2016-04-15 16:40:15 +00:00
|
|
|
|
|
|
|
|
2016-04-15 10:10:38 +00:00
|
|
|
|
2016-05-24 07:01:16 +00:00
|
|
|
}
|