added first pChart charts.
This commit is contained in:
BIN
libraries/chart/pChart/fonts/tahoma.ttf
Normal file
BIN
libraries/chart/pChart/fonts/tahoma.ttf
Normal file
Binary file not shown.
119
libraries/chart/pChart/pCache.class
Normal file
119
libraries/chart/pChart/pCache.class
Normal file
@@ -0,0 +1,119 @@
|
|||||||
|
<?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));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
?>
|
3489
libraries/chart/pChart/pChart.class
Normal file
3489
libraries/chart/pChart/pChart.class
Normal file
File diff suppressed because it is too large
Load Diff
260
libraries/chart/pChart/pData.class
Normal file
260
libraries/chart/pChart/pData.class
Normal 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);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
?>
|
25
libraries/chart/pma_pchart_chart.php
Normal file
25
libraries/chart/pma_pchart_chart.php
Normal file
@@ -0,0 +1,25 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
require_once 'pma_chart.php';
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Base class for every chart implemented using pChart.
|
||||||
|
*/
|
||||||
|
class PMA_pChart_Chart extends PMA_Chart
|
||||||
|
{
|
||||||
|
protected $imageEncoded;
|
||||||
|
|
||||||
|
protected $fontPath = './libraries/chart/pChart/fonts/';
|
||||||
|
|
||||||
|
function __construct($options = null)
|
||||||
|
{
|
||||||
|
parent::__construct($options);
|
||||||
|
}
|
||||||
|
|
||||||
|
function toString()
|
||||||
|
{
|
||||||
|
return '<img id="pChartPicture1" src="data:image/png;base64,'.$this->imageEncoded.'" />';
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
?>
|
68
libraries/chart/pma_pchart_pie.php
Normal file
68
libraries/chart/pma_pchart_pie.php
Normal file
@@ -0,0 +1,68 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
require_once 'pma_pchart_chart.php';
|
||||||
|
|
||||||
|
class PMA_pChart_Pie extends PMA_pChart_Chart
|
||||||
|
{
|
||||||
|
private $border1Width = 7;
|
||||||
|
private $border2Width = 5;
|
||||||
|
|
||||||
|
function __construct($titleText, $data, $options = null)
|
||||||
|
{
|
||||||
|
parent::__construct($options);
|
||||||
|
|
||||||
|
require_once './libraries/chart/pChart/pData.class';
|
||||||
|
require_once './libraries/chart/pChart/pChart.class';
|
||||||
|
|
||||||
|
// Dataset definition
|
||||||
|
$DataSet = new pData;
|
||||||
|
$DataSet->AddPoint(array_values($data),"Serie1");
|
||||||
|
$DataSet->AddPoint(array_keys($data),"Serie2");
|
||||||
|
$DataSet->AddAllSeries();
|
||||||
|
$DataSet->SetAbsciseLabelSerie("Serie2");
|
||||||
|
|
||||||
|
// Initialise the graph
|
||||||
|
$Test = new pChart($this->width, $this->height);
|
||||||
|
foreach ($this->colors as $key => $color) {
|
||||||
|
$Test->setColorPalette(
|
||||||
|
$key,
|
||||||
|
hexdec(substr($color, 1, 2)),
|
||||||
|
hexdec(substr($color, 3, 2)),
|
||||||
|
hexdec(substr($color, 5, 2))
|
||||||
|
);
|
||||||
|
}
|
||||||
|
$Test->setFontProperties($this->fontPath.'tahoma.ttf', 8);
|
||||||
|
$Test->drawFilledRoundedRectangle(
|
||||||
|
$this->border1Width,
|
||||||
|
$this->border1Width,
|
||||||
|
$this->width - $this->border1Width,
|
||||||
|
$this->height - $this->border1Width,
|
||||||
|
5,240,240,240);
|
||||||
|
$Test->drawRoundedRectangle(
|
||||||
|
$this->border1Width,
|
||||||
|
$this->border1Width,
|
||||||
|
$this->width - $this->border1Width,
|
||||||
|
$this->height - $this->border1Width,
|
||||||
|
5,230,230,230);
|
||||||
|
|
||||||
|
// Draw the pie chart
|
||||||
|
$Test->AntialiasQuality = 0;
|
||||||
|
$Test->setShadowProperties(2,2,200,200,200);
|
||||||
|
//$Test->drawFlatPieGraphWithShadow($DataSet->GetData(),$DataSet->GetDataDescription(),180,160,120,PIE_PERCENTAGE,8);
|
||||||
|
//$Test->drawBasicPieGraph($DataSet->GetData(),$DataSet->GetDataDescription(),180,160,120,PIE_PERCENTAGE,255,255,218,2);
|
||||||
|
$Test->drawPieGraph($DataSet->GetData(),$DataSet->GetDataDescription(),180,160,120,PIE_PERCENTAGE,FALSE,60,30,10,1);
|
||||||
|
$Test->clearShadow();
|
||||||
|
|
||||||
|
$Test->drawTitle(10,20,$titleText,0,0,0);
|
||||||
|
$Test->drawPieLegend(340,15,$DataSet->GetData(),$DataSet->GetDataDescription(),250,250,250);
|
||||||
|
|
||||||
|
ob_start();
|
||||||
|
imagepng($Test->Picture);
|
||||||
|
$output = ob_get_contents();
|
||||||
|
ob_end_clean();
|
||||||
|
|
||||||
|
$this->imageEncoded = base64_encode($output);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
?>
|
Reference in New Issue
Block a user