From 4bd9ac0cc77d8088f9c8f4e4a1043798ad1259fc Mon Sep 17 00:00:00 2001 From: Michael RICOIS Date: Thu, 1 Apr 2010 16:33:24 +0000 Subject: [PATCH] integration radar --- includes/commentaires/commentaires.php | 68 ++++++++++++++++++++++---- 1 file changed, 59 insertions(+), 9 deletions(-) diff --git a/includes/commentaires/commentaires.php b/includes/commentaires/commentaires.php index 3c9d2263d..a5db5c349 100644 --- a/includes/commentaires/commentaires.php +++ b/includes/commentaires/commentaires.php @@ -67,28 +67,38 @@ function commentaires_lien($content){ } function commentaires_graph($id, $titre, $ratios = array() ){ - $pattern = '/(Rs?)\[(.*)]#(.{1})/'; $data = array(); - $data['x'] = commentaires_graph_x(); + $pattern = '/(Rs?)\[(.*)]#(.{1})/'; foreach($ratios as $ratio){ - FB::log($ratio, 'ratio'); + //FB::log($ratio, 'ratio'); if( preg_match($pattern, $ratio, $matches) ){ $typeRatio = $matches[1]; $numRatio = $matches[2]; $typeElement = $matches[3]; $titreRatio = commentaires_graph_lib($numRatio); - switch($typeRatio){ - case 'R' : $titreRatio.= ' - Entreprise'; break; - case 'Rs' : $titreRatio.= ' - Secteur'; break; + if ($typeElement != 'R'){ + switch($typeRatio){ + case 'R' : $titreRatio.= ' - Entreprise'; break; + case 'Rs' : $titreRatio.= ' - Secteur'; break; + } + }else{ + $supPattern = '/\(.*?\)/'; + $titreRatio = preg_replace($supPattern, '', $titreRatio); } $data['y'][] = array( 'titre' => $titreRatio, 'data' => commentaires_graph_y($typeRatio, $numRatio), 'style' => $typeElement, ); + //FB::log($data['y'], 'data'); } } - $output = commentaires_graph_xy($id, $titre, $data); + $data['x'] = commentaires_graph_x(); + if ($typeElement == 'R'){ + $output = commentaires_graph_radar($id, $titre, $data); + } else { + $output = commentaires_graph_xy($id, $titre, $data); + } return $output; } @@ -110,19 +120,59 @@ function commentaires_graph_x(){ function commentaires_graph_y($typeRatio, $numRatio){ global $ratiosEntrep, $ratiosSecteur; - FB::log($typeRatio, 'typeRatio'); + //FB::log($typeRatio, 'typeRatio'); switch($typeRatio){ case 'R' : $tabRatio = $ratiosEntrep; break; case 'Rs' : $tabRatio = $ratiosSecteur; break; } $output = array(); foreach($tabRatio as $key => $val){ - FB::log($val['r'.$numRatio], 'val'); + //FB::log($val['r'.$numRatio], 'val'); $output[$key] = $val['r'.$numRatio]; } return $output; } + +function commentaires_graph_radar($id, $titre, $data){ + require_once 'phpchartdir/phpchartdir.php'; + $path = PATH_SITE.'/cache/imgcache/'; + $file = $id.'.png'; + if(count($data)<=1){ + $output = 0; + }else{ + FB::log($data, 'data'); + //Tri des données + foreach($data['y'] as $yKey => $y){ + $i = 0; + foreach($y['data'] as $val){ + $dataTri[$data['x'][$i]] = $val; + $i++; + } + ksort($dataTri); + $data['y'][$yKey]['data'] = array_values($dataTri); + } + sort($data['x']); + FB::log($data, 'data'); + foreach($data['y'] as $val){ + $num = count($val['data'])-1; + $gdata[] = $val['data'][$num]; + $labels[] = $val['titre']; + } + } + FB::log($gdata, 'gdata'); + $c = new PolarChart(500, 350); + $c->setPlotArea(250, 175, 150); + $c->addAreaLayer($gdata, 0x9999ff); + $c->angularAxis->setLabels($labels); + if( $c->makeChart($path.$file) === true ){ + $output = $file; + }else{ + $output = false; + } + return $output; +} + function commentaires_graph_xy($id, $titre, $data){ require_once 'phpchartdir/phpchartdir.php'; $path = PATH_SITE.'/cache/imgcache/';