[gosa.git] / gosa-core / plugins / generic / statistics / chartClasses / class_categoryActionOverTime.inc
1 <?php
3 class categoryActionsOverTime extends statChart
4 {
5 protected $title = 'Plugin usage over time';
7 function __construct(&$config)
8 {
9 parent::__construct($config);
10 $this->graphName = get_class();
11 }
14 /*! \brief Generates the line-graph which displays the plugin usage over time.
15 */
16 function render()
17 {
18 $lineMax = 100;
19 $gData = $this->graphData;
20 $errorMax = (max($gData['errorsPerInterval']) < 100)? 100:max($gData['errorsPerInterval']);
21 $dataSet = new pData;
22 $seriesCnt = 0;
23 foreach($gData['actionsGraph'] as $category => $entriesPerDate){
24 if(empty($category) || in_array_strict($category, $this->skipSeries)) continue;
26 // Add results to our data set.
27 $dataSet->AddPoint($entriesPerDate, $category);
28 $dataSet->SetSerieName($this->getCategoryTranslation($category), $category);
29 $dataSet->AddSerie($category);
31 // Detect maximum value, to adjust the Y-Axis
32 $tmpMax = max($entriesPerDate);
33 if($tmpMax > $lineMax) $lineMax = $tmpMax;
34 $seriesCnt ++;
35 }
37 // Keep a list of all selecteable data-series, to allow the user to disable
38 // or enable series on demand.
39 $this->seriesList = array();
40 foreach($gData['actionsGraph'] as $key => $data){
41 $this->seriesList[$key] = $this->getCategoryTranslation($key);
42 }
43 $this->seriesList['errorsPerInterval'] = _("Error");
45 // Create a dataSet containing all series
46 $allSeriesDataSet = clone $dataSet;
47 if(!in_array_strict('errorsPerInterval', $this->skipSeries)){
48 $allSeriesDataSet->AddPoint($gData['errorsPerInterval'], 'Errors');
49 $allSeriesDataSet->SetSerieName(_('Error'), 'Errors');
50 $allSeriesDataSet->AddSerie('Errors');
51 }
53 // Add timeline
54 $dataSet->AddPoint($gData['dates'], 'date');
55 $dataSet->SetAbsciseLabelSerie('date');
57 // Read graph from cache?
58 $pCache = new pCache($this->cachePath);
59 if($this->enableCaching && $pCache->IsInCache(get_class(),$allSeriesDataSet->GetData())){
60 $filename = $pCache->GetHash(get_class(),$allSeriesDataSet->GetData());
61 $filename = '/var/spool/gosa/'.$filename;
62 if(file_exists($filename) && is_readable($filename)){
63 $this->graphID = preg_replace("/[^0-9]/","",microtime(TRUE)).rand(0,99999);
64 session::set('statistics::graphFile'.$this->graphID,$filename);
65 return;
66 }
67 }
69 $chart = new pChart(900,230);
70 $chart->setFixedScale(0.000,$lineMax);
71 $chart->setFontProperties("./themes/default/fonts/LiberationSans-Regular.ttf",10);
72 $chart->setGraphArea(50,28,630,200);
73 $chart->drawFilledRoundedRectangle(7,7,693,223,5,240,240,240);
74 $chart->drawRoundedRectangle(5,5,695,225,5,230,230,230);
75 $chart->drawGraphArea(255,255,255,TRUE);
76 $chart->drawGrid(4,TRUE,200,200,200,50);
77 $chart->drawTreshold(0,143,55,72,TRUE,TRUE);
78 $chart->drawTitle(50,22,_($this->title),50,50,50,585);
79 $chart->drawScale($dataSet->GetData(),$dataSet->GetDataDescription(),SCALE_NORMAL,150,150,150,TRUE,0,2, TRUE);
81 // Only draw this graph if we've at least one series to draw!
82 if($seriesCnt){
83 $chart->drawFilledLineGraph($dataSet->GetData(),$dataSet->GetDataDescription(),50,TRUE);
84 }
86 // Do we've to add the errors series?
87 // If we have to, then add the error-data-series.
88 // and set the color for the new error-series to red.
89 if(!in_array_strict('errorsPerInterval', $this->skipSeries)){
91 // Set the color for the error Series to 'red'.
92 // This has to be done before drawing the legend.
93 $chart->setColorPalette($seriesCnt,255,0,0);
95 $dataSet->AddPoint($gData['errorsPerInterval'], 'Errors');
96 $dataSet->SetSerieName(_('Error'), 'Errors');
97 $dataSet->AddSerie('Errors');
98 }
100 $chart->drawLegend(720,0,$dataSet->GetDataDescription(),255,255,255);
102 // Draw the error graph on top of the other graphs now.
103 // But remove the category-graph before.
104 if(!in_array_strict('errorsPerInterval', $this->skipSeries)){
106 // Remove all graph series and add the error-series, then draw the new graph.
107 // (It is not relevant if it was really added before, so we simply remove all series!)
108 foreach($gData['actionsGraph'] as $category => $data){
109 $dataSet->RemoveSerie($category);
110 }
111 $chart->setFixedScale(0,$errorMax);
112 $chart->drawRightScale($dataSet->GetData(),$dataSet->GetDataDescription(),SCALE_NORMAL,120,150,150,TRUE,0,2, TRUE);
113 $chart->drawBarGraph($dataSet->GetData(),$dataSet->GetDataDescription());
114 }
116 // Generate new and unique graph id
117 $this->graphID = preg_replace("/[^0-9]/","",microtime(TRUE));
118 $file = '/tmp/graph_'.$this->graphID;
119 $chart->Render($file);
120 session::set('statistics::graphFile'.$this->graphID,$file);
121 $pCache->WriteToCache(get_class(),$allSeriesDataSet->GetData(),$chart);
123 return;
124 }
126 }
127 ?>