2009-03-12 Esteban Sanchez <estebans@artica.es>

* reporting/pandora_graph.php: Added to repository. New interface to
        abstract pandora from the chart engines. This would make easier a
        engine changing in the future.

        * reporting/pchart_graph.php: Added to repository. Specific class to
        use pChart engine for Pandora. First working version.

        * reporting/pChart/pCache.class, reporting/pChart/pDaita.class: Added
        to repository. pChart engine
        
        * reporting/pChart/pChart.class: Added to repository. pChart engine
        slightly modified and adopted to Pandora needs.



git-svn-id: https://svn.code.sf.net/p/pandora/code/trunk@1526 c3f86ba8-e40f-0410-aaad-9ba5e7f4b01f
This commit is contained in:
esanchezm 2009-03-12 09:29:42 +00:00
parent e79dd9af23
commit 5d6f786bc3
7 changed files with 5270 additions and 1617 deletions

View File

@ -1,3 +1,18 @@
2009-03-12 Esteban Sanchez <estebans@artica.es>
* reporting/pandora_graph.php: Added to repository. New interface to
abstract pandora from the chart engines. This would make easier a
engine changing in the future.
* reporting/pchart_graph.php: Added to repository. Specific class to
use pChart engine for Pandora. First working version.
* reporting/pChart/pCache.class, reporting/pChart/pDaita.class: Added
to repository. pChart engine
* reporting/pChart/pChart.class: Added to repository. pChart engine
slightly modified and adopted to Pandora needs.
2009-03-12 Esteban Sanchez <estebans@artica.es> 2009-03-12 Esteban Sanchez <estebans@artica.es>
* include/auth/mysql.php: Added a cache to is_user_admin(). * include/auth/mysql.php: Added a cache to is_user_admin().

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,120 @@
<?php
/*
pCache - Faster renderding using data cache
Copyright (C) 2008 Jean-Damien POGOLOTTI
Version 1.1.2 last updated on 06/17/08
http://pchart.sourceforge.net
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 1,2,3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
Class initialisation :
pCache($CacheFolder="Cache/")
Cache management :
IsInCache($Data)
GetFromCache($ID,$Data)
WriteToCache($ID,$Data,$Picture)
DeleteFromCache($ID,$Data)
ClearCache()
Inner functions :
GetHash($ID,$Data)
*/
/* pCache class definition */
class pCache
{
var $HashKey = "";
var $CacheFolder = "Cache/";
/* Create the pCache object */
function pCache($CacheFolder="Cache/")
{
$this->CacheFolder = $CacheFolder;
}
/* This function is clearing the cache folder */
function ClearCache()
{
if ($handle = opendir($this->CacheFolder))
{
while (false !== ($file = readdir($handle)))
{
if ( $file != "." && $file != ".." )
unlink($this->CacheFolder.$file);
}
closedir($handle);
}
}
/* This function is checking if we have an offline version of this chart */
function IsInCache($ID,$Data,$Hash="")
{
if ( $Hash == "" )
$Hash = $this->GetHash($ID,$Data);
if ( file_exists($this->CacheFolder.$Hash) )
return(TRUE);
else
return(FALSE);
}
/* This function is making a copy of drawn chart in the cache folder */
function WriteToCache($ID,$Data,$Picture)
{
$Hash = $this->GetHash($ID,$Data);
$FileName = $this->CacheFolder.$Hash;
imagepng($Picture->Picture,$FileName);
}
/* This function is removing any cached copy of this chart */
function DeleteFromCache($ID,$Data)
{
$Hash = $this->GetHash($ID,$Data);
$FileName = $this->CacheFolder.$Hash;
if ( file_exists($FileName ) )
unlink($FileName);
}
/* This function is retrieving the cached picture if applicable */
function GetFromCache($ID,$Data)
{
$Hash = $this->GetHash($ID,$Data);
if ( $this->IsInCache("","",$Hash ) )
{
$FileName = $this->CacheFolder.$Hash;
header('Content-type: image/png');
@readfile($FileName);
exit();
}
}
/* This function is building the graph unique hash key */
function GetHash($ID,$Data)
{
$mKey = "$ID";
foreach($Data as $key => $Values)
{
$tKey = "";
foreach($Values as $Serie => $Value)
$tKey = $tKey.$Serie.$Value;
$mKey = $mKey.md5($tKey);
}
return(md5($mKey));
}
}
?>

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,260 @@
<?php
/*
pData - Simplifying data population for pChart
Copyright (C) 2008 Jean-Damien POGOLOTTI
Version 1.13 last updated on 08/17/08
http://pchart.sourceforge.net
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 1,2,3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
Class initialisation :
pData()
Data populating methods :
ImportFromCSV($FileName,$Delimiter=",",$DataColumns=-1,$HasHeader=FALSE,$DataName=-1)
AddPoint($Value,$Serie="Serie1",$Description="")
Series manipulation methods :
AddSerie($SerieName="Serie1")
AddAllSeries()
RemoveSerie($SerieName="Serie1")
SetAbsciseLabelSerie($SerieName = "Name")
SetSerieName($Name,$SerieName="Serie1")
+ SetSerieSymbol($Name,$Symbol)
SetXAxisName($Name="X Axis")
SetYAxisName($Name="Y Axis")
SetXAxisFormat($Format="number")
SetYAxisFormat($Format="number")
SetXAxisUnit($Unit="")
SetYAxisUnit($Unit="")
removeSerieName($SerieName)
removeAllSeries()
Data retrieval methods :
GetData()
GetDataDescription()
*/
/* pData class definition */
class pData
{
var $Data;
var $DataDescription;
function pData()
{
$this->Data = "";
$this->DataDescription = "";
$this->DataDescription["Position"] = "Name";
$this->DataDescription["Format"]["X"] = "number";
$this->DataDescription["Format"]["Y"] = "number";
$this->DataDescription["Unit"]["X"] = NULL;
$this->DataDescription["Unit"]["Y"] = NULL;
}
function ImportFromCSV($FileName,$Delimiter=",",$DataColumns=-1,$HasHeader=FALSE,$DataName=-1)
{
$handle = @fopen($FileName,"r");
if ($handle)
{
$HeaderParsed = FALSE;
while (!feof($handle))
{
$buffer = fgets($handle, 4096);
$buffer = str_replace(chr(10),"",$buffer);
$buffer = str_replace(chr(13),"",$buffer);
$Values = split($Delimiter,$buffer);
if ( $buffer != "" )
{
if ( $HasHeader == TRUE && $HeaderParsed == FALSE )
{
if ( $DataColumns == -1 )
{
$ID = 1;
foreach($Values as $key => $Value)
{ $this->SetSerieName($Value,"Serie".$ID); $ID++; }
}
else
{
$SerieName = "";
foreach($DataColumns as $key => $Value)
$this->SetSerieName($Values[$Value],"Serie".$Value);
}
$HeaderParsed = TRUE;
}
else
{
if ( $DataColumns == -1 )
{
$ID = 1;
foreach($Values as $key => $Value)
{ $this->AddPoint(intval($Value),"Serie".$ID); $ID++; }
}
else
{
$SerieName = "";
if ( $DataName != -1 )
$SerieName = $Values[$DataName];
foreach($DataColumns as $key => $Value)
$this->AddPoint($Values[$Value],"Serie".$Value,$SerieName);
}
}
}
}
fclose($handle);
}
}
function AddPoint($Value,$Serie="Serie1",$Description="")
{
if (is_array($Value) && count($Value) == 1)
$Value = $Value[0];
$ID = 0;
for($i=0;$i<=count($this->Data);$i++)
{ if(isset($this->Data[$i][$Serie])) { $ID = $i+1; } }
if ( count($Value) == 1 )
{
$this->Data[$ID][$Serie] = $Value;
if ( $Description != "" )
$this->Data[$ID]["Name"] = $Description;
elseif (!isset($this->Data[$ID]["Name"]))
$this->Data[$ID]["Name"] = $ID;
}
else
{
foreach($Value as $key => $Val)
{
$this->Data[$ID][$Serie] = $Val;
if (!isset($this->Data[$ID]["Name"]))
$this->Data[$ID]["Name"] = $ID;
$ID++;
}
}
}
function AddSerie($SerieName="Serie1")
{
if ( !isset($this->DataDescription["Values"]) )
{
$this->DataDescription["Values"][] = $SerieName;
}
else
{
$Found = FALSE;
foreach($this->DataDescription["Values"] as $key => $Value )
if ( $Value == $SerieName ) { $Found = TRUE; }
if ( !$Found )
$this->DataDescription["Values"][] = $SerieName;
}
}
function AddAllSeries()
{
unset($this->DataDescription["Values"]);
if ( isset($this->Data[0]) )
{
foreach($this->Data[0] as $Key => $Value)
{
if ( $Key != "Name" )
$this->DataDescription["Values"][] = $Key;
}
}
}
function RemoveSerie($SerieName="Serie1")
{
if ( !isset($this->DataDescription["Values"]) )
return(0);
$Found = FALSE;
foreach($this->DataDescription["Values"] as $key => $Value )
{
if ( $Value == $SerieName )
unset($this->DataDescription["Values"][$key]);
}
}
function SetAbsciseLabelSerie($SerieName = "Name")
{
$this->DataDescription["Position"] = $SerieName;
}
function SetSerieName($Name,$SerieName="Serie1")
{
$this->DataDescription["Description"][$SerieName] = $Name;
}
function SetXAxisName($Name="X Axis")
{
$this->DataDescription["Axis"]["X"] = $Name;
}
function SetYAxisName($Name="Y Axis")
{
$this->DataDescription["Axis"]["Y"] = $Name;
}
function SetXAxisFormat($Format="number")
{
$this->DataDescription["Format"]["X"] = $Format;
}
function SetYAxisFormat($Format="number")
{
$this->DataDescription["Format"]["Y"] = $Format;
}
function SetXAxisUnit($Unit="")
{
$this->DataDescription["Unit"]["X"] = $Unit;
}
function SetYAxisUnit($Unit="")
{
$this->DataDescription["Unit"]["Y"] = $Unit;
}
function SetSerieSymbol($Name,$Symbol)
{
$this->DataDescription["Symbol"][$Name] = $Symbol;
}
function removeSerieName($SerieName)
{
if ( isset($this->DataDescription["Description"][$SerieName]) )
unset($this->DataDescription["Description"][$SerieName]);
}
function removeAllSeries()
{
foreach($this->DataDescription["Values"] as $Key => $Value)
unset($this->DataDescription["Values"][$Key]);
}
function GetData()
{
return($this->Data);
}
function GetDataDescription()
{
return($this->DataDescription);
}
}
?>

View File

@ -0,0 +1,82 @@
<?php
// Pandora FMS - the Flexible Monitoring System
// ============================================
// Copyright (c) 2008 Artica Soluciones Tecnologicas, http://www.artica.es
// Copyright (c) 2008 Esteban Sánchez, <estebans@artica.es>
// Please see http://pandora.sourceforge.net for full contribution list
// This program is free software; you can redistribute it and/or
// modify it under the terms of the GNU General Public License
// as published by the Free Software Foundation for version 2.
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
// You should have received a copy of the GNU General Public License
// along with this program; if not, write to the Free Software
// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
abstract class PandoraGraphAbstract {
public $width = 300;
public $height = 200;
public $data;
public $legend = false;
public $fontpath;
public $three_dimensions = true;
public $graph_color = array ();
public $xaxis_interval = 1;
public $yaxis_interval = 5;
public $xaxis_format = 'numeric';
public $yaxis_format = 'numeric';
public $show_title = false;
public $show_legend = false;
public $background_gradient = false;
public $title = "";
public $subtitle = "";
public $stacked = false;
public $zoom = 85;
public $events = false;
public $alert_top = false;
public $alert_bottom = false;
public $date_format = "d/m";
public $max_value = 0;
public $min_value = 0;
public $background_color = '#FFFFFF';
public $border = true;
abstract protected function pie_graph ();
abstract protected function horizontal_bar_graph ();
abstract protected function vertical_bar_graph ();
abstract protected function sparse_graph ($period, $avg_only, $min_value, $max_value, $unit_name);
abstract protected function single_graph ();
abstract protected function combined_graph ($values, $events, $alerts, $unit_name, $max_value, $stacked);
abstract protected function progress_bar ($value, $color);
}
function get_graph_engine ($period = 3600) {
global $config;
if (file_exists ('pchart_graph.php')) {
require_once ('pchart_graph.php');
$engine = new PchartGraph ();
if (isset ($config['graphics_palette']))
$engine->load_palette ($config['graphics_palette']);
} else {
exit;
}
$engine->graph_color[1] = $config['graph_color1'];
$engine->graph_color[2] = $config['graph_color2'];
$engine->graph_color[3] = $config['graph_color3'];
if ($period <= 86400)
$engine->date_format = 'g:iA';
elseif ($period <= 604800)
$engine->date_format = 'd/m';
else
$engine->date_format = 'd/m/y';
return $engine;
}
?>

View File

@ -0,0 +1,492 @@
<?php
// Pandora FMS - the Flexible Monitoring System
// ============================================
// Copyright (c) 2008 Artica Soluciones Tecnológicas, http://www.artica.es
// Copyright (c) 2008 Esteban Sánchez, <estebans@artica.es>
// Please see http://pandora.sourceforge.net for full contribution list
// This program is free software; you can redistribute it and/or
// modify it under the terms of the GNU General Public License
// as published by the Free Software Foundation for version 2.
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
// You should have received a copy of the GNU General Public License
// along with this program; if not, write to the Free Software
// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
require_once ('pChart/pData.class');
require_once ('pChart/pChart.class');
class PchartGraph extends PandoraGraphAbstract {
public $palette_path = false;
private $graph = NULL;
private $dataset = NULL;
private $x1;
private $x2;
private $y1;
private $y2;
public function load_palette ($palette_path) {
$this->palette_path = $palette_path;
}
public function pie_graph () {
// dataset definition
$this->dataset = new pData;
$this->dataset->AddPoint ($this->data, "Serie1", $this->legend);
$this->dataset->AddPoint ($this->legend, "Serie2");
$this->dataset->AddAllSeries ();
$this->dataset->SetAbsciseLabelSerie ("Serie2");
// Initialise the graph
$this->graph = new pChart ($this->width, $this->height);
$this->graph->setFontProperties ($this->fontpath, 8);
if ($this->palette_path) {
$this->graph->loadColorPalette ($this->palette_path);
}
$this->add_background ();
// Draw the pie chart
if ($this->three_dimensions) {
$this->graph->drawPieGraph ($this->dataset->GetData (),
$this->dataset->GetDataDescription (),
$this->width / 2,
$this->height / 2 - 15, $this->zoom,
PIE_PERCENTAGE_LABEL, 5, 70, 20, 5);
} else {
$this->graph->drawFlatPieGraph ($this->dataset->GetData (),
$this->dataset->GetDataDescription (),
$this->width / 2,
$this->height / 2, $this->zoom,
PIE_PERCENTAGE_LABEL, 5);
}
if ($this->show_legend) {
$this->graph->drawPieLegend (10, 10, $this->dataset->GetData (),
$this->dataset->GetDataDescription (), 255, 255, 255);
}
$this->graph->Stroke ();
}
public function horizontal_bar_graph () {
// dataset definition
$this->dataset = new pData;
foreach ($this->data as $x => $y) {
$this->dataset->AddPoint ($y, "Serie1", $x);
}
$this->dataset->AddAllSeries ();
$this->dataset->SetXAxisFormat ("label");
$this->dataset->SetYAxisFormat ($this->yaxis_format);
// Initialise the graph
$this->graph = new pChart ($this->width, $this->height);
if ($this->palette_path) {
$this->graph->loadColorPalette ($this->palette_path);
}
$this->graph->setFontProperties ($this->fontpath, 8);
$this->add_background ();
$this->graph->drawGraphArea (255, 255, 255, true);
$this->graph->drawGrid (4, true, 230, 230, 230, 50);
// Draw the bar graph
$this->graph->setFontProperties ($this->fontpath, 8);
$this->graph->setFixedScale (0, max ($this->data));
$this->graph->drawOverlayBarGraphH ($this->dataset->GetData (),
$this->dataset->GetDataDescription (), 50);
// Finish the graph
$this->add_legend ();
$this->graph->Stroke ();
}
public function single_graph () {
// Dataset definition
$this->dataset = new pData;
$this->graph = new pChart ($this->width, $this->height);
foreach ($this->data as $x => $y) {
$this->dataset->AddPoint ($y, "Serie1", $x);
}
$color = $this->get_rgb_values ($this->graph_color[2]);
$this->graph->setColorPalette (0, $color['r'], $color['g'], $color['b']);
$this->dataset->AddAllSeries ();
if ($this->legend !== false) {
$this->dataset->SetSerieName ($this->legend[0], "Serie1");
}
if ($this->palette_path) {
$this->graph->loadColorPalette ($this->palette_path);
}
$this->graph->setFontProperties ($this->fontpath, 8);
$this->add_background ();
$this->dataset->SetXAxisFormat ($this->xaxis_format);
$this->dataset->SetYAxisFormat ($this->yaxis_format);
$this->graph->drawGraphArea (255, 255, 255, true);
if ($this->max_value == 0 || $this->max_value == 1)
$this->graph->setFixedScale (0, 1, 1);
$this->graph->drawScale ($this->dataset->GetData (),
$this->dataset->GetDataDescription (),
SCALE_START0, 80, 80, 80, true,
0, 0, false,
$this->xaxis_interval);
$this->graph->drawGrid (4, false, 0, 0, 0);
if ($this->max_value > 0) {
// Draw the graph
$this->graph->drawFilledLineGraph ($this->dataset->GetData (),
$this->dataset->GetDataDescription (),
50, true);
}
// Finish the graph
$this->add_legend ();
$this->add_events ();
$this->add_alert_levels ();
$this->graph->Stroke ();
}
public function sparse_graph ($period, $avg_only, $min_value, $max_value, $unit_name) {
// Dataset definition
$this->dataset = new pData;
$this->graph = new pChart ($this->width, $this->height);
$this->graph->setFontProperties ($this->fontpath, 8);
$this->legend = array ();
if ($avg_only) {
foreach ($this->data as $data) {
$this->dataset->AddPoint ($data['sum'], "AVG", $data['timestamp_bottom']);
}
} else {
foreach ($this->data as $data) {
$this->dataset->AddPoint ($data['sum'], "AVG", $data['timestamp_bottom']);
$this->dataset->AddPoint ($data['min'], "MIN");
$this->dataset->AddPoint ($data['max'], "MAX");
}
$this->legend[1] = __("Min. Value");
$this->legend[2] = __("Max. Value");
$this->dataset->SetSerieName (__("Min. Value"), "MIN");
$this->dataset->SetSerieName (__("Max. Value"), "MAX");
}
$this->set_colors ();
$this->dataset->SetXAxisFormat ('date');
$this->graph->setDateFormat ("Y");
$this->dataset->SetYAxisFormat ('metric');
$this->dataset->AddAllSeries ();
$this->dataset->SetSerieName (__("Avg. Value"), "AVG");
$this->legend[0] = __("Avg. Value");
if ($this->palette_path) {
$this->graph->loadColorPalette ($this->palette_path);
}
$this->add_background ();
$this->graph->drawGraphArea (255, 255, 255, true);
$this->xaxis_interval = ($this->xaxis_interval / 7 >= 1) ? ($this->xaxis_interval / 7) : 10;
$this->graph->drawScale ($this->dataset->GetData (),
$this->dataset->GetDataDescription (), SCALE_START0,
80, 80, 80, true, 0, 0, false,
$this->xaxis_interval);
/* NOTICE: The final "false" is a Pandora modificaton of pChart to avoid showing vertical lines. */
$this->graph->drawGrid (1, true, 225, 225, 225, 100, false);
// Draw the graph
$this->graph->drawFilledLineGraph ($this->dataset->GetData(), $this->dataset->GetDataDescription(), 50, true);
$this->add_legend ();
$this->add_events ("AVG");
$this->add_alert_levels ();
$this->graph->Stroke ();
}
public function vertical_bar_graph () {
// dataset definition
$this->dataset = new pData;
foreach ($this->data as $x => $y) {
$this->dataset->AddPoint ($y, "Serie1", $x);
}
$this->dataset->AddAllSeries ();
$this->dataset->SetAbsciseLabelSerie ();
$this->dataset->SetXAxisFormat ($this->xaxis_format);
$this->dataset->SetYAxisFormat ($this->yaxis_format);
// Initialise the graph
$this->graph = new pChart ($this->width, $this->height);
if ($this->palette_path) {
$this->graph->loadColorPalette ($this->palette_path);
}
$this->graph->setFontProperties ($this->fontpath, 8);
$this->add_background ();
$this->graph->drawGraphArea (255, 255, 255, true);
$this->graph->drawGrid (4, true, 230, 230, 230, 50);
// Draw the bar graph
$this->graph->setFontProperties ($this->fontpath, 8);
$this->graph->drawScale ($this->dataset->GetData (),
$this->dataset->GetDataDescription (),
SCALE_START0, 80, 80, 80,
true, 0, 0, false,
$this->xaxis_interval);
$this->graph->drawOverlayBarGraph ($this->dataset->GetData (),
$this->dataset->GetDataDescription (),
50);
$this->add_events ("Serie1");
$this->add_alert_levels ();
// Finish the graph
$this->graph->Stroke ();
}
public function combined_graph ($values, $events, $alerts, $unit_name, $max_value, $stacked) {
set_time_limit (0);
// Dataset definition
$this->dataset = new pData;
$this->graph = new pChart ($this->width, $this->height);
foreach ($this->data as $i => $data) {
foreach ($data as $j => $value) {
$this->dataset->AddPoint ($value, $this->legend[$i],
$values[$j]['timestamp_bottom']);
}
}
foreach ($this->legend as $name)
$this->dataset->setSerieName($name, $name);
$this->set_colors ();
$this->graph->setFontProperties ($this->fontpath, 8);
$this->dataset->SetXAxisFormat ('date');
$this->dataset->SetYAxisFormat ('metric');
$this->dataset->AddAllSeries ();
$this->add_background ();
$this->graph->drawGraphArea (255, 255, 255, true);
// Draw the graph
if ($stacked == 1) {
$this->graph->drawScale ($this->dataset->GetData (),
$this->dataset->GetDataDescription (),
SCALE_ADDALL, 80, 80, 80, true,
0, 0, false,
$this->xaxis_interval);
/* Stacked mode are only supported in bar charts */
//$this->graph->DivisionWidth = ($this->x2 - $this->x1) / sizeof ($this->data[0]);
$this->graph->drawStackedBarGraph ($this->dataset->GetData (),
$this->dataset->GetDataDescription (),
50);
} else if ($stacked == 2) {
$this->graph->drawScale ($this->dataset->GetData (),
$this->dataset->GetDataDescription (),
SCALE_START0, 80, 80, 80, true, 0, 0, false,
$this->xaxis_interval);
$this->graph->drawLineGraph ($this->dataset->GetData (),
$this->dataset->GetDataDescription ());
} else {
$this->graph->drawScale ($this->dataset->GetData (),
$this->dataset->GetDataDescription (),
SCALE_START0, 80, 80, 80, true, 0, 0, false,
$this->xaxis_interval);
$this->graph->drawFilledCubicCurve ($this->dataset->GetData(),
$this->dataset->GetDataDescription(), 0.1, 50, true);
}
$this->add_legend ();
$this->add_events ($this->legend[0]);
$this->add_alert_levels ();
$this->graph->Stroke ();
}
public function progress_bar ($value, $color) {
set_time_limit (0);
// Dataset definition
$this->graph = new pChart ($this->width, $this->height);
$this->graph->setFontProperties ($this->fontpath, 8);
$radius = ($this->height > 18) ? 10 : 0;
$ratio = (int) $value / 100 * $this->width;
/* Color stuff */
$r = hexdec (substr ($this->background_color, 1, 2));
$g = hexdec (substr ($this->background_color, 3, 2));
$b = hexdec (substr ($this->background_color, 5, 2));
/* Actual percentage */
$this->graph->drawFilledRectangle (0, 0, $this->width,
$this->height, 255, 255, 255, false, 0);
$this->graph->drawFilledRoundedRectangle (0, 0, $this->width,
$this->height, $radius, $r, $g, $b);
$r = hexdec (substr ($color, 1, 2));
$g = hexdec (substr ($color, 3, 2));
$b = hexdec (substr ($color, 5, 2));
$this->graph->drawFilledRoundedRectangle (0, 0, $ratio,
$this->height, $radius, $r, $g, $b);
/* Under this value, the rounded rectangle is painted great */
if ($ratio <= 16) {
/* Clean a bit of pixels */
for ($i = 0; $i < 7; $i++) {
$this->graph->drawLine (0, $i, 6 - $i, $i, 255, 255, 255);
}
$end = $this->height - 1;
for ($i = 0; $i < 7; $i++) {
$this->graph->drawLine (0, $end - $i, 5 - $i, $end - $i, 255, 255, 255);
}
}
if ($this->show_title) {
$this->graph->drawTextBox (0, 0, $this->width, $this->height,
$this->title, 0, 255, 255, 255, ALIGN_CENTER, true);
}
if ($this->border) {
$this->graph->drawRoundedRectangle (0, 0, $this->width - 1 , $this->height - 1,
$radius, 0, 0, 0);
}
$this->graph->Stroke ();
}
/* Gets an array with each the components of a RGB string */
private static function get_rgb_values ($rgb_string) {
$color = array ('r' => 0, 'g' => 0, 'b' => 0);
$offset = 0;
if ($rgb_string[0] == '#')
$offset = 1;
$color['r'] = hexdec (substr ($rgb_string, $offset, 2));
$color['g'] = hexdec (substr ($rgb_string, $offset + 2, 2));
$color['b'] = hexdec (substr ($rgb_string, $offset + 4, 2));
return $color;
}
private function add_alert_levels () {
if ($this->alert_top !== false) {
$this->graph->drawTreshold ($this->alert_top, 57,
96, 255, true, true, 4,
"Alert top");
}
if ($this->alert_bottom !== false) {
$this->graph->drawTreshold ($this->alert_bottom, 7,
96, 255, true, true, 4,
"Alert bottom");
}
}
private function add_events ($serie = "Serie1") {
if (! $this->events)
return;
/* Unfortunatelly, the events must be draw manually */
$first = $this->dataset->Data[0]["Name"];
$len = count ($this->dataset->Data) - 1;
$last = $this->dataset->Data[$len]["Name"];
$ylen = $this->y2 - $this->y1;
foreach ($this->data as $i => $data) {
/* Finally, check if there were events */
if (! $data['events'])
continue;
$x1 = (int) ($this->x1 + $i * $this->graph->DivisionWidth);
$y1 = (int) ($this->y2 - ($this->dataset->Data[$i][$serie] * $this->graph->DivisionRatio));
$this->graph->drawFilledCircle ($x1, $y1, 1.5, 255, 0, 0);
if ($y1 == $this->y2)
/* Lines in the same dot fails */
continue;
$this->graph->drawDottedLine ($x1 - 1, $y1,
$x1 - 1, $this->y2,
5, 255, 150, 150);
}
}
private function add_background () {
if ($this->graph == NULL)
return;
$this->graph->setDateFormat ($this->date_format);
$this->x1 = ($this->width > 300) ? 30 : 35;
$this->y1 = ($this->height > 200) ? 25 : 10;
$this->x2 = ($this->width > 300) ? $this->width - 30 : $this->width - 15;
$this->y2 = ($this->height > 200) ? $this->height - 25 : $this->height - 25;
if ($this->max_value > 10000)
$this->x1 += 20;
if ($this->background_gradient)
$this->graph->drawGraphAreaGradient (233, 243, 210, 50, TARGET_BACKGROUND);
else
$this->graph->drawGraphArea (255, 255, 255, true);
if ($this->show_title) {
$this->y1 += 30;
}
$this->graph->setFontProperties ($this->fontpath, 6);
$size = $this->graph->getLegendBoxSize ($this->dataset->GetDataDescription ());
if (is_array ($size)) {
while ($size[1] > $this->y1)
$this->y1 += (int) $size[1] / 2;
if ($this->y1 > $this->y2) {
$this->y1 = $this->y2;
}
}
$this->graph->setGraphArea ($this->x1, $this->y1, $this->x2, $this->y2);
if ($this->show_title) {
$this->graph->setFontProperties ($this->fontpath, 10);
$this->graph->drawTextBox (0, 0, $this->width, 20, $this->title, 0,
255, 255, 255, ALIGN_LEFT, true, 0, 0, 0, 30);
$this->graph->setFontProperties ($this->fontpath, 9);
$this->graph->drawTextBox (0, 20, $this->width, 40, $this->subtitle,
0, 255, 255, 255, ALIGN_LEFT, true, 0, 0, 0, 0);
$this->graph->setFontProperties ($this->fontpath, 8);
}
/* This is a tiny watermark. Remove safely */
$this->graph->setFontProperties ($this->fontpath, 7);
$this->graph->drawTextBox ($this->width - 5, $this->height - 0,
$this->width - 240, $this->height - 0, 'Pandora FMS', 90,
154, 154, 154, ALIGN_BOTTOM_LEFT, false);
}
private function add_legend () {
if (! $this->show_title || $this->legend === false) {
return;
}
/* Add legend */
$this->graph->setFontProperties ($this->fontpath, 6);
$size = $this->graph->getLegendBoxSize ($this->dataset->GetDataDescription ());
$this->graph->drawLegend ($this->width - $size[0] - 32, 5,
$this->dataset->GetDataDescription (),
240, 240, 240);
}
private function set_colors () {
if ($this->graph == NULL)
return;
$color = $this->get_rgb_values ($this->graph_color[2]);
$this->graph->setColorPalette (0, $color['r'], $color['g'], $color['b']);
$color = $this->get_rgb_values ($this->graph_color[1]);
$this->graph->setColorPalette (1, $color['r'], $color['g'], $color['b']);
$color = $this->get_rgb_values ($this->graph_color[3]);
$this->graph->setColorPalette (2, $color['r'], $color['g'], $color['b']);
}
}
?>