diff --git a/manager/module/chart.php b/manager/module/chart.php index 1e03d6b..b40e03d 100755 --- a/manager/module/chart.php +++ b/manager/module/chart.php @@ -83,9 +83,10 @@ return array( 'ModuleError' => ManagerError::Success, - 'title' => 'Répartition des appels', + 'type' => 'pie', + 'title' => 'Répartition des appels', 'pointFormat' => '{series.name}: {point.percentage:.1f}%', - 'series' => array(array( + 'series' => array(array( 'colorByPoint' => true, 'data' => array( array( 'name' => 'Entrant', 'y' => $INCOMING ), @@ -144,9 +145,10 @@ return array( 'ModuleError' => ManagerError::Success, - 'title' => 'Répartition des types de communication', + 'type' => 'pie', + 'title' => 'Répartition des types de communication', 'pointFormat' => '{series.name}: {point.percentage:.1f}%', - 'series' => array(array( + 'series' => array(array( 'colorByPoint' => true, 'data' => array( array( 'name' => 'Appels', 'y' => $PHONE ), @@ -213,9 +215,10 @@ return array( 'ModuleError' => ManagerError::Success, - 'title' => 'Répartition des genres', + 'type' => 'pie', + 'title' => 'Répartition des genres', 'pointFormat' => '{series.name}: {point.percentage:.1f}%', - 'series' => array(array( + 'series' => array(array( 'colorByPoint' => true, 'data' => array( array( 'name' => 'Homme', 'y' => $H ), @@ -322,6 +325,7 @@ return array( 'ModuleError' => ManagerError::Success, + 'type' => 'column', 'xlabels' => $labels, 'title' => 'Répartition des ages', 'zoom' => 'x', @@ -435,6 +439,7 @@ return array( 'ModuleError' => ManagerError::Success, + 'type' => 'bar', 'xlabels' => $labels, 'title' => 'Répartition des relations', 'pointFormat' => '{series.name}: {point.y:.1f}%', @@ -517,9 +522,10 @@ return array( 'ModuleError' => ManagerError::Success, + 'type' => 'column', 'xlabels' => $labels, 'title' => 'Répartition dans la semaine', - 'pointFormat' => '{series.name}: {point.y:1f} communications', + 'pointFormat' => '{series.name}: {point.y:1f}', 'series' => array( array( // En fonction des appels 'name' => 'appels', @@ -567,7 +573,7 @@ $labels = array(); // labels des heures $times = array(); // heure en fonction du log - for( $h = 0 ; $h < 23 ; $h++ ){ + for( $h = 0 ; $h < 24 ; $h++ ){ array_push($labels, $h.'h00'); $times[ $h*60 ] = 0; // xx H 00 @@ -605,6 +611,7 @@ return array( 'ModuleError' => ManagerError::Success, + 'type' => 'column', 'xlabels' => $labels, 'zoom' => 'x', 'title' => 'Répartition dans la journée', diff --git a/view/js/charts-min.js b/view/js/charts-min.js index ec8923c..94e1307 100644 --- a/view/js/charts-min.js +++ b/view/js/charts-min.js @@ -1,5 +1,5 @@ -var subPhone=$('section[data-sublink="phone"]');subPhone.style.display="flex";subPhone.style.flexWrap="wrap";subPhone.style.justifyContent="space-around";Chart.defaults.global.responsive=!1;Chart.defaults.global.title.display=!1;Chart.defaults.global.tooltips.footerFontSize=0;Chart.defaults.global.onClick=function(a,d){console.log(a);null!=d[0]&&console.log(d[0]._datasetIndex,d[0]._index)};subject=273; -var charts="sexe direction type ages relations weekdays timeofday".split(" "),types="pie pie pie column bar column column".split(" "),canvas=[],instances=[],plotOptions=[{pie:{showInLegend:!0,innerSize:"50%",allowPointSelect:!0,cursor:"pointer",startAngle:-90,endAngle:90,dataLabels:{enabled:!1,distance:10,format:"{point.name}: {point.percentage:.1f} %",style:{color:"black",textShadow:"0 0 2px white"}}}}];plotOptions[1]=plotOptions[0];plotOptions[2]=plotOptions[0]; -plotOptions[3]={column:{shadow:!1,borderWidth:0}};plotOptions[5]={column:{shadow:!1,borderWidth:0}};plotOptions[5].column.stacking="normal";plotOptions[4]={bar:{allowPointSelect:!0,cursor:"pointer"}};plotOptions[6]={};for(var c in charts)canvas[c]=document.createElement("div"),canvas[c].id=charts[c],canvas[c].style.width=canvas[c].style.height="pie"!=types[c]?"40em":"30em",canvas[c].style.margin="2em",subPhone.appendChild(canvas[c]); -for(c=0;c{point.name}: {point.percentage:.1f} %",style:{color:"black",textShadow:"0 0 2px white"}}}},column:{column:{shadow:!1,borderWidth:0,stacking:null}},weekdays:{column:{shadow:!1,borderWidth:0,stacking:"normal"}},bar:{bar:{allowPointSelect:!0, +cursor:"pointer"}}},c;for(c in charts)canvas[c]=document.createElement("div"),canvas[c].id=charts[c],canvas[c].style.width=canvas[c].style.height="30em",canvas[c].style.margin="2em",subPhone.appendChild(canvas[c]); +for(c=0;c{point.name}: {point.percentage:.1f} %', style: { color: 'black', textShadow: '0 0 2px white' } } -} } ]; +} }; -plotOptions[1] = plotOptions[0]; // PIE -plotOptions[2] = plotOptions[0]; // PIE +/* (2) Pour les graphiques de type 'column' */ +plotOptions['column'] = { column: { shadow: false, borderWidth: 0, stacking: null } }; -// AGES + WEEKDAY -plotOptions[3] = { column: { shadow: false, borderWidth: 0 } }; -plotOptions[5] = { column: { shadow: false, borderWidth: 0 } }; -plotOptions[5].column.stacking = 'normal'; +/* (3) Pour le graphique des jours de la semaine */ +plotOptions['weekdays'] = { column: { shadow: false, borderWidth: 0, stacking: 'normal' } }; -// RELATIONS -plotOptions[4] = { bar: { allowPointSelect: true, cursor: 'pointer' } }; - -// TIMEOFDAY -plotOptions[6] = {}; +/* (4) Pour les graphiques de type 'bar' */ +plotOptions['bar'] = { bar: { allowPointSelect: true, cursor: 'pointer' } }; -/* [1] On crée les conteneurs + + +/* [2] On crée les conteneurs =========================================================*/ for( var c in charts ){ canvas[c] = document.createElement('div'); canvas[c].id = charts[c]; - // canvas[c].width = canvas[c].height = ( types[c] == 'bar' ) ? 500 : 300; - canvas[c].style.width = canvas[c].style.height = ( types[c] != 'pie' ) ? '40em' : '30em'; + canvas[c].style.width = canvas[c].style.height = '30em'; canvas[c].style.margin = '2em'; subPhone.appendChild( canvas[c] ); } -/* [2] Pour chaque graphique, on récupère les données et on les affiche +/* [3] Pour chaque graphique, on récupère les données et on les affiche =========================================================*/ for( var c = 0 ; c < charts.length ; c++ ){ @@ -91,23 +78,37 @@ for( var c = 0 ; c < charts.length ; c++ ){ if( response.ModuleError != 0 ) return false; - /* [2] On construit les données + /* [4] On construit les données =========================================================*/ var data = { labels: response.labels, datasets: response.datasets }; - /* [3] On construit notre graphique + // Si c'est un 'donut', on met plus petit + if( response.type == 'pie' ) + canvas[c].style.width = canvas[c].style.height = '20em'; + + + /* [5] On construit les options du graphique =========================================================*/ /* (1) On définit les options */ var options = { - chart: { renderTo: canvas[c], type: types[c] }, + chart: { renderTo: canvas[c], type: response.type }, series: response.series, - plotOptions: plotOptions[c], xAxis: {}, yAxis: {} }; + // Gestion des options + if( plotOptions[charts[c]] != null ){ + console.log(1, charts[c]); + options.plotOptions = plotOptions[charts[c]]; + } + else if( plotOptions[response.type] != null ){ + console.log(2, charts[c]); + options.plotOptions = plotOptions[response.type]; + } + // types de données if( response.xaxis != null ) options.xAxis = response.xaxis; if( response.yaxis != null ) options.yAxis = response.yaxis; @@ -125,12 +126,13 @@ for( var c = 0 ; c < charts.length ; c++ ){ // pointFormat if( response.pointFormat != null ) options.tooltip = { pointFormat: response.pointFormat }; - console.log(options); - /* (2) On crée le graphique */ + + /* [6] On crée le graphique + =========================================================*/ instances[c] = new Highcharts.Chart(options); - }, null, c); + }, null, c); // On passe @c au @handler pour l'avoir dans le scope