Code

Updated graph handling in case of no data
authorhickert <hickert@594d385d-05f5-0310-b6e9-bd551577e9d8>
Thu, 26 Aug 2010 11:17:09 +0000 (11:17 +0000)
committerhickert <hickert@594d385d-05f5-0310-b6e9-bd551577e9d8>
Thu, 26 Aug 2010 11:17:09 +0000 (11:17 +0000)
git-svn-id: https://oss.gonicus.de/repositories/gosa/trunk@19462 594d385d-05f5-0310-b6e9-bd551577e9d8

gosa-core/plugins/generic/statistics/chartClasses/class_memoryUsageChart.inc
gosa-core/plugins/generic/statistics/chartClasses/class_pieChart1.inc
gosa-core/plugins/generic/statistics/statistics.tpl

index da16ec54e9c092d81de8c1415202b58503315a5d..ac6b8d3c3e797eaa436e1b3c0ba7a5c7c69d3db7 100644 (file)
@@ -23,11 +23,19 @@ class memoryUsageChart extends statChart
      */ 
     function render()
     {
+
         // Add series data to dataSet        
         $dataSet = new pData;  
-        $max = 0;
+        $max = 1;
         foreach($this->series as $seriesName => $seriesDesc){
-            if(isset($this->graphData[$this->dataName][$seriesName])){
+
+            // Check if we've useable series data
+            $renderable = 
+                (isset($this->graphData[$this->dataName][$seriesName])) && 
+                (count($this->graphData[$this->dataName][$seriesName]));
+
+            // Add series if it has at least one result
+            if($renderable){
                 $dataSet->AddPoint($this->graphData[$this->dataName][$seriesName],$seriesName);
                 $dataSet->SetSerieName($seriesDesc,$seriesName);
                 if($max < max($this->graphData[$this->dataName][$seriesName])) $max = max($this->graphData[$this->dataName][$seriesName]);
@@ -50,7 +58,7 @@ class memoryUsageChart extends statChart
         }
 
         $chart = new pChart(800,230);  
-        $chart->setFixedScale(0.0001,($max*1.1));  
+        $chart->setFixedScale(0,$max);  
         $chart->setFontProperties("./themes/default/fonts/LiberationSans-Regular.ttf",10);  
         $chart->setGraphArea(50,30,585,200);  
         $chart->drawFilledRoundedRectangle(7,7,693,223,5,240,240,240);  
index e63ecb6e423d2d9d29db5c2b1e8cd83a525b264f..5bbce475b8692fad7204156553ec4d20fa74cc9e 100644 (file)
@@ -28,12 +28,15 @@ class pieChart1 extends statChart
         
         // Detect max value and throw out entries less than 1% 
         //  the will else be unreadable
-        $max = max($data);
+
+        $max = (count($data)) ? max($data) : 1;
         $pos = 0;
         foreach($data as $key => $count){
             if($pos >=7 || ($count / $max)*100 < 1) break;
             $pos ++;
         }
+
+        $this->graphID = 0;
  
         $dataRes = array_slice($data,0,$pos);
 
@@ -48,6 +51,8 @@ class pieChart1 extends statChart
             $keys[$id] = $this->getCategoryTranslation($cat);
         }
 
+        if(!count($data)) return;
+
         // Dataset definition   
         $dataSet = new pData;  
         $dataSet->AddPoint($values,"Serie1");  
@@ -76,8 +81,8 @@ class pieChart1 extends statChart
         $chart->setFontProperties($this->font,10); 
         if(count($data)) {
             $chart->drawPieGraph($dataSet->GetData(),$dataSet->GetDataDescription(),($x/3),($y/2)-10,($y/2),PIE_PERCENTAGE,TRUE,50,20,6);  
+            $chart->drawPieLegend(($x/3*2),15,$dataSet->GetData(),$dataSet->GetDataDescription(),255,255,255);
         }
-        $chart->drawPieLegend(($x/3*2),15,$dataSet->GetData(),$dataSet->GetDataDescription(),255,255,255);
 
         // Store graph data
         $this->graphID = preg_replace("/[^0-9]/","",microtime(TRUE));
index 0ad79788e93a278b47301eb4e6851d66d5abac3a..670bc8f5a5f0fdc29955a2540b9223af35efa857 100644 (file)
             <td>
                 {if isset($staticChart1_ID) && $staticChart1_ID}
                     <img src='plugins/statistics/getGraph.php?id={$staticChart1_ID}'>
+                {else}
+                    <div style='height:200px; width: 400px;'>
+                        <i>{t}No statistic data for given period{/t}</i>
+                    </div>
                 {/if}
             </td>
             <td>
                 {if isset($staticChart2_ID) && $staticChart2_ID}
                     <img src='plugins/statistics/getGraph.php?id={$staticChart2_ID}'>
+                {else}
+                    <div style='height:200px; width: 400px;'>
+                        <i>{t}No statistic data for given period{/t}</i>
+                    </div>
                 {/if}
             </td>
         </tr>