From 0ad3839b5345f85876b4ef53ab95409105c86f0e Mon Sep 17 00:00:00 2001 From: Michael RICOIS Date: Mon, 5 Jul 2010 12:49:54 +0000 Subject: [PATCH] Retravail des gaphiques histo --- includes/commentaires/commentaires.php | 136 ++++++++++++------------- 1 file changed, 64 insertions(+), 72 deletions(-) diff --git a/includes/commentaires/commentaires.php b/includes/commentaires/commentaires.php index 30e3c5e6f..b9fe6637c 100644 --- a/includes/commentaires/commentaires.php +++ b/includes/commentaires/commentaires.php @@ -306,8 +306,11 @@ function commentaires_graph_stacked($id, $titre, $strRatios) { function commentaires_graph_histo($id, $titre, $strRatios){ - global $graphCouleurs; + global $graphCouleurs, $bilansInfos, $ratiosEntrep, $ratiosSecteur, + $tabProjection; + //FB::log($graphCouleurs, 'HISTO : graphCouleurs'); + //Gestion des couleurs if(count($graphCouleurs)>0){ $couleurs = $graphCouleurs; } else { @@ -315,59 +318,60 @@ function commentaires_graph_histo($id, $titre, $strRatios){ } $ratios = explode(',', $strRatios); $data = array(); + $dataInfos = array(); + $nbRatio = 0; //Détection des ratios - $pattern = '/(Rs?)\[(.*)]#(.{1})/'; + $patternR = '/(Rs?)\[(.*)]#(.{1})/'; + $patternP = '/(.*)_Y#(.{1})/'; foreach ( $ratios as $ratio ) { - if( preg_match($pattern, $ratio, $matches) ){ + //Ratios secteur et entreprise + if( preg_match($patternR, $ratio, $matches) ){ $typeRatio = $matches[1]; $numRatio = $matches[2]; $titreRatio = commentaires_graph_lib($numRatio); - switch($typeRatio){ - case 'R' : $titreRatio.= ' - Entreprise'; break; - case 'Rs' : $titreRatio.= ' - Secteur'; break; + switch ( $typeRatio ){ + case 'R' : + $titreRatio.= ' - Entreprise'; + $tabRatio = $ratiosEntrep; + break; + case 'Rs' : + $titreRatio.= ' - Secteur'; + $tabRatio = $ratiosSecteur; + break; } - $data['y'][] = array( + + //Informations données + $dataInfos[$nbRatio] = array( 'titre' => $titreRatio, - 'data' => commentaires_graph_y($typeRatio, $numRatio), 'style' => $matches[3], ); - $data['x'] = commentaires_graph_x(); - } - } - if ( count($data['x'])>0 ){ - $diff = 10000; - $xPrec = 0; - for ( $index = 0 ; $index < count($data['x']); $index++ ){ - $x = $data['x'][$index]; - FB::log($xPrec, 'xPrec'); - FB::log($x, 'x'); - FB::log($diff, 'diff'); - if ( $diff < 10000 ){ - FB::log($index,'Suppression'); - array_splice($data['x'], $index, 1); - foreach ($data['y'] as $yIndex => $yData){ - array_splice($data['y'][$yIndex]['data'], $index, 1); - } - //$index = $index-1; - } else { - $xPrec = $x; - } - if( $xPrec != 0 ){ $diff = $xPrec-$x; } - $index++; - } - } - //Détection des projections - $pattern = '/(.*)_Y#(.{1})/'; - foreach ( $ratios as $ratio ){ - if (preg_match($pattern, $ratio, $matches) ){ + //Assignation données + $xPrec = 0; + foreach ( $tabRatio as $key => $valRatio ){ + $index = (int)substr($bilansInfos[$key]['dateCloture'],0,4); + ($xPrec != 0) ? $diff = $xPrec-$index : $diff = 1; + if ($diff == 1){ + $data[$index][$nbRatio] = $valRatio['r'.$numRatio]; + } + $xPrec = $index; + } + $nbRatio++; + //Ratios de projection + } elseif ( preg_match($patternP, $ratio, $matches) ){ + $titreRatio = $matches[1]; - $data['y'][] = array( + $dataInfos[$nbRatio] = array( 'titre' => $titreRatio.' - Projection', - 'data' => commentaires_graph_y('projection', $titreRatio), 'style' => $matches[2], ); - $data['x'] = commentaires_graphp_x($titreRatio); + $tabRatio = $tabProjection[$titreRatio.'_Y']; + krsort($tabRatio); + foreach ( $tabRatio as $key => $valRatio ){ + $index = (int)substr($key,0,4); + $data[$index][$nbRatio] = $valRatio; + } + $nbRatio++; } } FB::log($data, 'data'); @@ -375,21 +379,17 @@ function commentaires_graph_histo($id, $titre, $strRatios){ require_once 'phpchartdir/phpchartdir.php'; $path = PATH_SITE.'/cache/imgcache/'; $file = $id.'.png'; - if(count($data)<=1){ - $output = 0; - }else{ - //Tri des données - foreach($data['y'] as $yKey => $y){ - $i = 0; - foreach($y['data'] as $val){ - $dataTri[$data['x'][$i]] = $val; - $i++; + if ( count($data)<=1 ){ + $output = false; + } else { + ksort($data); + $labelsX = array_keys($data); + $valuesY = array(); + for ( $i = 0; $i < $nbRatio ; $i++ ){ + foreach ( $data as $values ){ + $valuesY[$i][] = isset($values[$i]) ? (int)$values[$i] : 0; } - ksort($dataTri); - $data['y'][$yKey]['data'] = array_values($dataTri); } - sort($data['x']); - //Génération du graphique $c = new XYChart(548, 350); $c->addTitle($titre, 'times.ttf', 10); @@ -397,18 +397,10 @@ function commentaires_graph_histo($id, $titre, $strRatios){ $c->yAxis->setWidth(2); $c->xAxis->setTitle('Années'); $c->xAxis->setWidth(2); + $c->xAxis->setLabels($labelsX); $legendObj = $c->addLegend2(25, 25, -2, "times.ttf", 9); $legendObj->setBackground(Transparent, Transparent); $c->setPlotArea(110, 90, 300, 200); - //Génération des labels - $labelsX = array(); - foreach($data['x'] as $x){ - $annee = substr($x, 0, 4); - $mois = substr($x, 4, 2); - $jour = substr($x, 6, 2); - $labelsX[] = $annee; - } - //Application layer pour line $lineLayer = $c->addLineLayer2(Side); $lineLayer->setBorderColor(Transparent, softLighting(Left)); @@ -416,20 +408,15 @@ function commentaires_graph_histo($id, $titre, $strRatios){ //Application layer pour bar $barLayer = $c->addBarLayer2(Side); $barLayer->setBorderColor(Transparent, softLighting(Left)); - //FB::log($data,'histo-Data'); - $i = 0; - foreach($data['y'] as $ydata){ + for ( $i = 0; $i < $nbRatio ; $i++ ){ //FB::log($couleurs[$i], 'Couleur'); - if ( $ydata['style'] == 'H' ){ - $barLayer->addDataSet($ydata['data'], $couleurs[$i], $ydata['titre']); - } else if ( $ydata['style'] == 'L' ){ - $dataSetObj = $lineLayer->addDataSet($ydata['data'], $couleurs[$i], $ydata['titre']); + if ( $dataInfos[$i]['style'] == 'H' ){ + $barLayer->addDataSet($valuesY[$i], $couleurs[$i], $dataInfos[$i]['titre']); + } else if ( $dataInfos[$i]['style'] == 'L' ){ + $dataSetObj = $lineLayer->addDataSet($valuesY[$i], $couleurs[$i], $dataInfos[$i]['titre']); $dataSetObj->setDataSymbol(SquareSymbol, 7); } - - $i++; } - $c->xAxis->setLabels($labelsX); if( $c->makeChart($path.$file) === true ){ $output = $file; } else { @@ -521,6 +508,11 @@ function commentaires_graphp_x($ratio){ return $output; } +function dateBilanAAAA($value){ + return (int)substr($value, 0, 4); +} + + function commentaires_graph_x(){ global $bilansInfos; $output = array();