summary | shortlog | log | commit | commitdiff | tree
raw | patch | inline | side by side (parent: 9b23eb7)
raw | patch | inline | side by side (parent: 9b23eb7)
author | hickert <hickert@594d385d-05f5-0310-b6e9-bd551577e9d8> | |
Tue, 24 Aug 2010 08:21:07 +0000 (08:21 +0000) | ||
committer | hickert <hickert@594d385d-05f5-0310-b6e9-bd551577e9d8> | |
Tue, 24 Aug 2010 08:21:07 +0000 (08:21 +0000) |
-Added self-made legend
git-svn-id: https://oss.gonicus.de/repositories/gosa/trunk@19430 594d385d-05f5-0310-b6e9-bd551577e9d8
git-svn-id: https://oss.gonicus.de/repositories/gosa/trunk@19430 594d385d-05f5-0310-b6e9-bd551577e9d8
gosa-core/plugins/generic/statistics/class_statistics.inc | patch | blob | history | |
gosa-core/plugins/generic/statistics/statistics.tpl | patch | blob | history |
diff --git a/gosa-core/plugins/generic/statistics/class_statistics.inc b/gosa-core/plugins/generic/statistics/class_statistics.inc
index 677b0b24f3a8ce3e3dd37b535f7bb68d352b087e..93ba75459cd73ddccd6803984bfe0c2bc067ab76 100644 (file)
var $graphIDs = array(); // IDs for created grpah
var $skipSeries = array(); // Graph series which should be skipped
var $seriesListPerGraph = array(); // Series names per graph
+ var $graphLegends = array(); // A self-made legend
// Legend colors
var $legendR = 235;
var $legendG = 235;
var $legendB = 235;
+ // Pre define the used chart colors
+ var $legendColors =
+ array(
+ array(127,127,116),
+ array(114,176,180),
+ array(0,124,143),
+ array(20,67,93),
+ array(39,10,43),
+ array(82,124,148),
+ array(97,152,183),
+ array(115,173,207),
+ array(144,196,226),
+ array(174,216,240));
+
+
// Font used in graphs
var $font = "./themes/default/fonts/LiberationSans-Regular.ttf";
}
+ $smarty->assign('legendColors', $this->legendColors);
+ $smarty->assign('graphLegends', $this->graphLegends);
$smarty->assign('seriesListPerGraph', $this->seriesListPerGraph);
$smarty->assign('skipSeries', $this->skipSeries);
$smarty->assign('graphIDs', $this->graphIDs);
/*! \brief Prepares the graph data we've received from the rpc-service.
* This method will construct a usable data-array with converted
- * date strings.
+ * date strings, cleaned up categories.
*/
function prepareGraphData($res)
{
+ // Dummy, please check later if it is still required.
+ $this->skipSeries[1] = array();
+ $this->skipSeries[2] = array();
+ $this->skipSeries[3] = array();
+ $this->skipSeries[4] = array();
+ $this->skipSeries[5] = array();
+
/* Build up array which represents the amount of errors per
* interval.
*/
}
ksort($gData['actionsPerInterval'][$category]);
}
- $this->skipSeries[1] = array();
- $this->skipSeries[2] = array();
- $this->skipSeries[3] = array();
- $this->skipSeries[4] = array();
- $this->skipSeries[5] = array();
-
// Clean data from unusable categories like ('terminals workstations, ...')
foreach($gData as $serieName => $seriesData){
*/
function generateActionsGraph($gData)
{
- $lineMax = 100;
- $errorMax = (max($gData['errorsPerInterval']) < 100)? 100:max($gData['errorsPerInterval']);
+
+ // Prepare self-made legend data
+ $legendData = array();
+
+ $lineMax = 10;
+ $errorMax = max($gData['errorsPerInterval']);
$dataSet = new pData;
$seriesCnt = 0;
$gID = 2;
+ $chart = new pChart(800,230);
foreach($gData['actionsPerInterval'] as $category => $entriesPerDate){
- if(empty($category) || in_array($category, $this->skipSeries[$gID])) continue;
-
- // Add results to our data set.
- $dataSet->AddPoint($entriesPerDate, $category);
- $dataSet->SetSerieName($this->getCategoryTranslation($category), $category);
- $dataSet->AddSerie($category);
+ if(empty($category)) continue;
+
+ // Add entry to legendData array.
+ $desc = $this->getCategoryTranslation($category);
+
+ // Set series color
+ $color = $this->legendColors[$seriesCnt];
+ $legendData[$seriesCnt] = array('name' => $category,'desc'=>$desc,'color' => $color);
+ list($r,$g,$b) = $color;
+ $chart->setColorPalette($seriesCnt,$r,$g,$b);
+
+ // Do not add graph data for skipped series
+ if(!in_array($category, $this->skipSeries[$gID])){
+ $dataSet->AddPoint($entriesPerDate, $category);
+ $dataSet->SetSerieName($desc, $category);
+ $dataSet->AddSerie($category);
+
+ // Detect maximum value, to adjust the Y-Axis
+ $tmpMax = max($entriesPerDate);
+ if($tmpMax > $lineMax) $lineMax = $tmpMax;
+ }
- // Detect maximum value, to adjust the Y-Axis
- $tmpMax = max($entriesPerDate);
- if($tmpMax > $lineMax) $lineMax = $tmpMax;
$seriesCnt ++;
}
// Add timeline
$dataSet->AddPoint($gData['dates'], 'date');
$dataSet->SetAbsciseLabelSerie('date');
-
- $chart = new pChart(800,230);
$chart->setFixedScale(0.000,$lineMax);
$chart->setFontProperties("./themes/default/fonts/LiberationSans-Regular.ttf",10);
$chart->setGraphArea(50,30,585,200);
// Set the color for the error Series to 'red'.
// This has to be done before drawing the legend.
$chart->setColorPalette($seriesCnt,255,0,0);
-
$dataSet->AddPoint($gData['errorsPerInterval'], 'Errors');
$dataSet->SetSerieName(_('Error'), 'Errors');
$dataSet->AddSerie('Errors');
- }
-
- // Draw legend, but only if there is something to draw!
- if($seriesCnt || !in_array('errorsPerInterval', $this->skipSeries[$gID])){
- $chart->drawLegend(650,30,$dataSet->GetDataDescription(),255,255,255);
}
+ // Add entry to legendData array.
+ $legendData[$seriesCnt] = array('name' => 'errorsPerInterval','desc'=>_('Error'),'color' => array(255,0,0));
+
// Draw the error graph on top of the other graphs now.
// But remove the category-graph before.
if(!in_array('errorsPerInterval', $this->skipSeries[$gID])){
$this->seriesListPerGraph[$gID][$key] = $this->getCategoryTranslation($key);
}
$this->seriesListPerGraph[$gID]['errorsPerInterval'] = _("Error");
-
+
+ // Create self-made legend with checkboxes to be able to select the desired graph series.
+ $this->graphLegends[$gID] = $this->generateLegend($legendData,$gID, TRUE);
return;
}
+ function generateLegend($legendData,$gID, $useCheckboxes = FALSE)
+ {
+ $str = "";
+ $str .= "<table>";
+ foreach($legendData as $id => $data){
+
+ $label = $data['desc'];
+ $name = $data['name'];
+ if(count($data['color'])){
+ list($r,$g,$b) = $data['color'];
+ $color = "rgba({$r},{$g},{$b},1)";
+ }else{
+ $color = "rgba(255,255,255,1);";
+ }
+ $colorDiv = "<div style='width:8px; height:8px; background-color: {$color}'>";
+
+ if($useCheckboxes){
+ $checked = (in_array($name, $this->skipSeries[$gID]))? '':'checked';
+ $checkbox = "<input type='checkbox' name='addSeries_{$gID}_{$name}' value='1'
+ onClick='document.mainform.submit();' {$checked}>";
+ }
+
+ $str .= "<tr>";
+ $str .= "<td>{$checkbox}</td><td style='vertical-align: middle;'>{$colorDiv}</td><td>{$label}</td>\n";
+ $str .= "</tr>";
+ }
+ $str.="</table>";
+ return($str);
+ }
+
+
/*! \brief Generates a graph about system informations.
*/
function generateSystemStatsGraph($gData, $key = "", $series= array(), $title = "", $gID=0 )
$dataSet->SetAbsciseLabelSerie('date');
$chart = new pChart(800,230);
+ $this->loadColors($chart);
$chart->setFixedScale(0.0001,($max*1.1));
$chart->setFontProperties("./themes/default/fonts/LiberationSans-Regular.ttf",10);
$chart->setGraphArea(50,30,585,200);
// Initialise the graph
$chart = new pChart($x,$y);
+ $this->loadColors($chart);
$chart->setFontProperties($this->font,10);
$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(),
$chart->Render($file);
session::set('statistics::graphFile'.$this->graphIDs[$gID],$file);
}
+
+ function loadColors(&$graph)
+ {
+ $colors =
+ array(
+ array(227,227,216),
+ array(114,176,180),
+ array(0,124,143),
+ array(20,67,93),
+ array(39,10,43),
+ array(82,124,148),
+ array(97,152,183),
+ array(115,173,207),
+ array(144,196,226),
+ array(174,216,240));
+
+ foreach($this->legendColors as $key => $values){
+ list($R,$G,$B) = $values;
+ $graph->setColorPalette($key,$R,$G,$B);
+ }
+ }
}
?>
diff --git a/gosa-core/plugins/generic/statistics/statistics.tpl b/gosa-core/plugins/generic/statistics/statistics.tpl
index 4892b4fd1266198250fa92aaae256c20cb8ae3c0..b9cd6bfb85d08bfd5c0d1f4628cb03dddefdbe12 100644 (file)
{/if}
</td>
<td>
- {if isset($graphIDs.2) && $graphIDs.2}
- {foreach from=$seriesListPerGraph.2 key=key item=item}
- <input type='checkbox' name='addSeries_2_{$key}' value='1'
- onClick="document.mainform.submit();"
- {if !($key|in_array:$skipSeries.2)} checked {/if}>{$item}<br>
- {/foreach}
+ {if isset($graphLegends.2) && $graphIDs.2}
+ {$graphLegends.2}
{/if}
</td>
</tr>