restructured the code to be more OOP friendly
This commit is contained in:
@@ -2,22 +2,51 @@
|
||||
|
||||
require_once 'pma_chart.php';
|
||||
|
||||
include "pChart/pData.class";
|
||||
include "pChart/pChart.class";
|
||||
|
||||
/*
|
||||
* Base class for every chart implemented using pChart.
|
||||
*/
|
||||
class PMA_pChart_Chart extends PMA_Chart
|
||||
abstract class PMA_pChart_Chart extends PMA_Chart
|
||||
{
|
||||
protected $titleText;
|
||||
protected $data;
|
||||
|
||||
protected $dataSet;
|
||||
protected $chart;
|
||||
|
||||
protected $imageEncoded;
|
||||
|
||||
protected $fontPath = './libraries/chart/pChart/fonts/';
|
||||
|
||||
function __construct($options = null)
|
||||
public function __construct($titleText, $data, $options = null)
|
||||
{
|
||||
parent::__construct($options);
|
||||
}
|
||||
|
||||
function toString()
|
||||
$this->titleText = $titleText;
|
||||
$this->data = $data;
|
||||
}
|
||||
|
||||
abstract protected function prepareDataSet();
|
||||
abstract protected function prepareChart();
|
||||
|
||||
protected function render()
|
||||
{
|
||||
ob_start();
|
||||
imagepng($this->chart->Picture);
|
||||
$output = ob_get_contents();
|
||||
ob_end_clean();
|
||||
|
||||
$this->imageEncoded = base64_encode($output);
|
||||
}
|
||||
|
||||
public function toString()
|
||||
{
|
||||
$this->prepareDataSet();
|
||||
$this->prepareChart();
|
||||
$this->render();
|
||||
|
||||
return '<img id="pChartPicture1" src="data:image/png;base64,'.$this->imageEncoded.'" />';
|
||||
}
|
||||
}
|
||||
|
@@ -7,32 +7,30 @@ class PMA_pChart_Pie extends PMA_pChart_Chart
|
||||
private $border1Width = 7;
|
||||
private $border2Width = 5;
|
||||
|
||||
function __construct($titleText, $data, $options = null)
|
||||
protected function prepareDataSet()
|
||||
{
|
||||
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),"Values");
|
||||
$dataSet->AddPoint(array_keys($data),"Keys");
|
||||
$dataSet->AddAllSeries();
|
||||
$dataSet->SetAbsciseLabelSerie("Keys");
|
||||
$this->dataSet = new pData;
|
||||
$this->dataSet->AddPoint(array_values($this->data),"Values");
|
||||
$this->dataSet->AddPoint(array_keys($this->data),"Keys");
|
||||
$this->dataSet->AddAllSeries();
|
||||
$this->dataSet->SetAbsciseLabelSerie("Keys");
|
||||
}
|
||||
|
||||
protected function prepareChart()
|
||||
{
|
||||
// Initialise the graph
|
||||
$chart = new pChart($this->width, $this->height);
|
||||
$this->chart = new pChart($this->width, $this->height);
|
||||
foreach ($this->colors as $key => $color) {
|
||||
$chart->setColorPalette(
|
||||
$this->chart->setColorPalette(
|
||||
$key,
|
||||
hexdec(substr($color, 1, 2)),
|
||||
hexdec(substr($color, 3, 2)),
|
||||
hexdec(substr($color, 5, 2))
|
||||
);
|
||||
}
|
||||
$chart->setFontProperties($this->fontPath.'tahoma.ttf', 8);
|
||||
$chart->drawFilledRoundedRectangle(
|
||||
$this->chart->setFontProperties($this->fontPath.'tahoma.ttf', 8);
|
||||
$this->chart->drawFilledRoundedRectangle(
|
||||
$this->border1Width,
|
||||
$this->border1Width,
|
||||
$this->width - $this->border1Width,
|
||||
@@ -42,7 +40,7 @@ class PMA_pChart_Pie extends PMA_pChart_Chart
|
||||
$this->getBgColorComp(1),
|
||||
$this->getBgColorComp(2)
|
||||
);
|
||||
$chart->drawRoundedRectangle(
|
||||
$this->chart->drawRoundedRectangle(
|
||||
$this->border1Width,
|
||||
$this->border1Width,
|
||||
$this->width - $this->border1Width,
|
||||
@@ -50,22 +48,15 @@ class PMA_pChart_Pie extends PMA_pChart_Chart
|
||||
5,0,0,0);
|
||||
|
||||
// Draw the pie chart
|
||||
$chart->AntialiasQuality = 0;
|
||||
$chart->setShadowProperties(2,2,200,200,200);
|
||||
$this->chart->AntialiasQuality = 0;
|
||||
$this->chart->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);
|
||||
$chart->drawPieGraph($dataSet->GetData(),$dataSet->GetDataDescription(),180,160,120,PIE_PERCENTAGE,FALSE,60,30,10,1);
|
||||
$chart->clearShadow();
|
||||
$this->chart->drawPieGraph($this->dataSet->GetData(),$this->dataSet->GetDataDescription(),180,160,120,PIE_PERCENTAGE,FALSE,60,30,10,1);
|
||||
$this->chart->clearShadow();
|
||||
|
||||
$chart->drawTitle(20,20,$titleText,0,0,0);
|
||||
$chart->drawPieLegend(350,15,$dataSet->GetData(),$dataSet->GetDataDescription(),250,250,250);
|
||||
|
||||
ob_start();
|
||||
imagepng($chart->Picture);
|
||||
$output = ob_get_contents();
|
||||
ob_end_clean();
|
||||
|
||||
$this->imageEncoded = base64_encode($output);
|
||||
$this->chart->drawTitle(20,20,$this->titleText,0,0,0);
|
||||
$this->chart->drawPieLegend(350,15,$this->dataSet->GetData(),$this->dataSet->GetDataDescription(),250,250,250);
|
||||
}
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user