diff --git a/libraries/chart.lib.php b/libraries/chart.lib.php
index e36b338fb..a4b26a92c 100644
--- a/libraries/chart.lib.php
+++ b/libraries/chart.lib.php
@@ -55,7 +55,7 @@ function PMA_chart_profiling($data)
/*
* Formats a chart for query results page.
*/
-function PMA_chart_results($data)
+function PMA_chart_results($data, &$chartSettings)
{
$chartData = array();
$chart = null;
@@ -78,7 +78,7 @@ function PMA_chart_results($data)
}
}
- $chart = new PMA_pChart_bar($chartTitle, $chartData);
+ $chart = new PMA_pChart_bar($chartTitle, $chartData, $chartSettings);
}
else if (count($data[0]) == 3) {
// Three columns (x axis, y axis, series) in every row.
@@ -117,14 +117,15 @@ function PMA_chart_results($data)
}
}
- $chart = new PMA_pChart_stacked($chartTitle, $chartData);
+ $chart = new PMA_pChart_stacked($chartTitle, $chartData, $chartSettings);
}
else {
// unknown data
return;
}
- echo $chart->toString();
+ $chartSettings = $chart->getSettings();
+ return $chart->toString();
}
?>
diff --git a/libraries/chart/pma_chart.php b/libraries/chart/pma_chart.php
index d89ef139e..6202273be 100644
--- a/libraries/chart/pma_chart.php
+++ b/libraries/chart/pma_chart.php
@@ -3,50 +3,55 @@
class PMA_Chart
{
/*
- * The style of the chart title.
+ * The settings array. All the default values are here.
*/
- protected $titleStyle = 'font-size: 12px; font-weight: bold;';
+ protected $settings = array(
+ /*
+ * The style of the chart title.
+ */
+ 'titleStyle' => 'font-size: 12px; font-weight: bold;',
- /*
- * Colors for the different slices in the pie chart.
- */
- protected $colors = array(
- '#BCE02E',
- '#E0642E',
- '#E0D62E',
- '#2E97E0',
- '#B02EE0',
- '#E02E75',
- '#5CE02E',
- '#E0B02E',
- '#000000',
- '#0022E0',
- '#726CB1',
- '#481A36',
- '#BAC658',
- '#127224',
- '#825119',
- '#238C74',
- '#4C489B',
- '#1D674A',
- '#87C9BF',
+ /*
+ * Colors for the different slices in the pie chart.
+ */
+ 'colors' => array(
+ '#BCE02E',
+ '#E0642E',
+ '#E0D62E',
+ '#2E97E0',
+ '#B02EE0',
+ '#E02E75',
+ '#5CE02E',
+ '#E0B02E',
+ '#000000',
+ '#0022E0',
+ '#726CB1',
+ '#481A36',
+ '#BAC658',
+ '#127224',
+ '#825119',
+ '#238C74',
+ '#4C489B',
+ '#1D674A',
+ '#87C9BF',
+ ),
+
+ /*
+ * Chart background color.
+ */
+ 'bgColor' => '#E5E5E5',
+
+ /*
+ * The width of the chart.
+ */
+ 'width' => 520,
+
+ /*
+ * The height of the chart.
+ */
+ 'height' => 325,
);
- /*
- * Chart background color.
- */
- protected $bgColor = '#E5E5E5';
-
- /*
- * The width of the chart.
- */
- protected $width = 520;
-
- /*
- * The height of the chart.
- */
- protected $height = 325;
-
function __construct($options = null)
{
$this->handleOptions($options);
@@ -64,17 +69,37 @@ class PMA_Chart
if (is_null($options))
return;
- if (isset($options['bgColor']))
- $this->bgColor = $options['bgColor'];
- if (isset($options['width']))
- $this->width = $options['width'];
- if (isset($options['height']))
- $this->height = $options['height'];
+ $this->settings = array_merge($this->settings, $options);
+ }
+
+ function getTitleStyle()
+ {
+ return $this->settings['titleStyle'];
+ }
+
+ function getColors()
+ {
+ return $this->settings['colors'];
+ }
+
+ function getWidth()
+ {
+ return $this->settings['width'];
+ }
+
+ function getHeight()
+ {
+ return $this->settings['height'];
}
function getBgColorComp($component)
{
- return hexdec(substr($this->bgColor, ($component * 2) + 1, 2));
+ return hexdec(substr($this->settings['bgColor'], ($component * 2) + 1, 2));
+ }
+
+ function getSettings()
+ {
+ return $this->settings;
}
}
diff --git a/libraries/chart/pma_pchart_bar.php b/libraries/chart/pma_pchart_bar.php
index 39e385a47..613d8c2d1 100644
--- a/libraries/chart/pma_pchart_bar.php
+++ b/libraries/chart/pma_pchart_bar.php
@@ -2,12 +2,22 @@
require_once 'pma_pchart_chart.php';
+define('TOP', 0);
+define('RIGHT', 1);
+define('BOTTOM', 2);
+define('LEFT', 3);
+
class PMA_pChart_bar extends PMA_pChart_Chart
{
- private $labelHeight = 20;
+ public function __construct($titleText, $data, $options = null)
+ {
+ parent::__construct($titleText, $data, $options);
- // as in CSS (top, right, bottom, left)
- private $areaMargins = array(20, 20, 40, 60);
+ $this->settings['labelHeight'] = 20;
+
+ // as in CSS (top, right, bottom, left)
+ $this->settings['areaMargins'] = array(20, 20, 40, 60);
+ }
protected function prepareDataSet()
{
@@ -30,11 +40,16 @@ class PMA_pChart_bar extends PMA_pChart_Chart
protected function prepareChart()
{
// Initialise the graph
- $this->chart = new pChart($this->width, $this->height);
+ $this->chart = new pChart($this->getWidth(), $this->getHeight());
$this->chart->drawGraphAreaGradient(132,173,131,50,TARGET_BACKGROUND);
- $this->chart->setFontProperties($this->fontPath.'tahoma.ttf', 8);
- $this->chart->setGraphArea($this->areaMargins[3],$this->labelHeight + $this->areaMargins[0],$this->width - $this->areaMargins[1],$this->height - $this->areaMargins[2]);
+ $this->chart->setFontProperties($this->getFontPath().'tahoma.ttf', 8);
+ $this->chart->setGraphArea(
+ $this->getAreaMargin(LEFT),
+ $this->getLabelHeight() + $this->getAreaMargin(TOP),
+ $this->getWidth() - $this->getAreaMargin(RIGHT),
+ $this->getHeight() - $this->getAreaMargin(BOTTOM)
+ );
$this->chart->drawGraphArea(213,217,221,FALSE);
$this->chart->drawScale($this->dataSet->GetData(),$this->dataSet->GetDataDescription(),SCALE_ADDALL,213,217,221,TRUE,0,2,TRUE);
$this->chart->drawGraphAreaGradient(163,203,167,50);
@@ -44,10 +59,20 @@ class PMA_pChart_bar extends PMA_pChart_Chart
$this->chart->drawStackedBarGraph($this->dataSet->GetData(),$this->dataSet->GetDataDescription(),70);
// Draw the title
- $this->chart->drawTextBox(0,0,$this->width,$this->labelHeight,$this->titleText,0,255,255,255,ALIGN_CENTER,TRUE,0,0,0,30);
+ $this->chart->drawTextBox(0,0,$this->getWidth(),$this->getLabelHeight(),$this->titleText,0,255,255,255,ALIGN_CENTER,TRUE,0,0,0,30);
$this->chart->addBorder(2);
}
+
+ protected function getLabelHeight()
+ {
+ return $this->settings['labelHeight'];
+ }
+
+ protected function getAreaMargin($side)
+ {
+ return $this->settings['areaMargins'][$side];
+ }
}
?>
diff --git a/libraries/chart/pma_pchart_chart.php b/libraries/chart/pma_pchart_chart.php
index 356f435a4..8ff41fe49 100644
--- a/libraries/chart/pma_pchart_chart.php
+++ b/libraries/chart/pma_pchart_chart.php
@@ -18,14 +18,14 @@ abstract class PMA_pChart_Chart extends PMA_Chart
protected $imageEncoded;
- protected $fontPath = './libraries/chart/pChart/fonts/';
-
public function __construct($titleText, $data, $options = null)
{
parent::__construct($options);
$this->titleText = $titleText;
$this->data = $data;
+
+ $this->settings['fontPath'] = './libraries/chart/pChart/fonts/';
}
abstract protected function prepareDataSet();
@@ -49,6 +49,11 @@ abstract class PMA_pChart_Chart extends PMA_Chart
return '';
}
+
+ protected function getFontPath()
+ {
+ return $this->settings['fontPath'];
+ }
}
?>
diff --git a/libraries/chart/pma_pchart_pie.php b/libraries/chart/pma_pchart_pie.php
index 9b9f0d08c..bd93e8978 100644
--- a/libraries/chart/pma_pchart_pie.php
+++ b/libraries/chart/pma_pchart_pie.php
@@ -4,8 +4,13 @@ require_once 'pma_pchart_chart.php';
class PMA_pChart_Pie extends PMA_pChart_Chart
{
- private $border1Width = 7;
- private $border2Width = 5;
+ public function __construct($titleText, $data, $options = null)
+ {
+ parent::__construct($titleText, $data, $options);
+
+ $this->settings['border1Width'] = 7;
+ $this->settings['border2Width'] = 8;
+ }
protected function prepareDataSet()
{
@@ -20,8 +25,8 @@ class PMA_pChart_Pie extends PMA_pChart_Chart
protected function prepareChart()
{
// Initialise the graph
- $this->chart = new pChart($this->width, $this->height);
- foreach ($this->colors as $key => $color) {
+ $this->chart = new pChart($this->getWidth(), $this->getHeight());
+ foreach ($this->getColors() as $key => $color) {
$this->chart->setColorPalette(
$key,
hexdec(substr($color, 1, 2)),
@@ -29,22 +34,22 @@ class PMA_pChart_Pie extends PMA_pChart_Chart
hexdec(substr($color, 5, 2))
);
}
- $this->chart->setFontProperties($this->fontPath.'tahoma.ttf', 8);
+ $this->chart->setFontProperties($this->getFontPath().'tahoma.ttf', 8);
$this->chart->drawFilledRoundedRectangle(
- $this->border1Width,
- $this->border1Width,
- $this->width - $this->border1Width,
- $this->height - $this->border1Width,
+ $this->getBorder1Width(),
+ $this->getBorder1Width(),
+ $this->getWidth() - $this->getBorder1Width(),
+ $this->getHeight() - $this->getBorder1Width(),
5,
$this->getBgColorComp(0),
$this->getBgColorComp(1),
$this->getBgColorComp(2)
);
$this->chart->drawRoundedRectangle(
- $this->border1Width,
- $this->border1Width,
- $this->width - $this->border1Width,
- $this->height - $this->border1Width,
+ $this->getBorder2Width(),
+ $this->getBorder2Width(),
+ $this->getWidth() - $this->getBorder2Width(),
+ $this->getHeight() - $this->getBorder2Width(),
5,0,0,0);
// Draw the pie chart
@@ -58,6 +63,16 @@ class PMA_pChart_Pie extends PMA_pChart_Chart
$this->chart->drawTitle(20,20,$this->titleText,0,0,0);
$this->chart->drawPieLegend(350,15,$this->dataSet->GetData(),$this->dataSet->GetDataDescription(),250,250,250);
}
+
+ protected function getBorder1Width()
+ {
+ return $this->settings['border1Width'];
+ }
+
+ protected function getBorder2Width()
+ {
+ return $this->settings['border2Width'];
+ }
}
?>
diff --git a/libraries/chart/pma_pchart_stacked.php b/libraries/chart/pma_pchart_stacked.php
index b1b541091..d3fae5195 100644
--- a/libraries/chart/pma_pchart_stacked.php
+++ b/libraries/chart/pma_pchart_stacked.php
@@ -1,15 +1,15 @@
settings['legendLeftMargin'] = 10;
+ }
protected function prepareDataSet()
{
@@ -38,14 +38,19 @@ class PMA_pChart_stacked extends PMA_pChart_Chart
protected function prepareChart()
{
// Initialise the graph
- $this->chart = new pChart($this->width, $this->height);
+ $this->chart = new pChart($this->getWidth(), $this->getHeight());
$this->chart->drawGraphAreaGradient(132,173,131,50,TARGET_BACKGROUND);
- $this->chart->setFontProperties($this->fontPath.'tahoma.ttf', 8);
+ $this->chart->setFontProperties($this->getFontPath().'tahoma.ttf', 8);
$legendSize = $this->chart->getLegendBoxSize($this->dataSet->GetDataDescription());
- $this->chart->setGraphArea($this->areaMargins[3],$this->labelHeight + $this->areaMargins[0],$this->width - $this->areaMargins[1] - $legendSize[0],$this->height - $this->areaMargins[2]);
+ $this->chart->setGraphArea(
+ $this->getAreaMargin(LEFT),
+ $this->getLabelHeight() + $this->getAreaMargin(TOP),
+ $this->getWidth() - $this->getAreaMargin(RIGHT) - $legendSize[0],
+ $this->getHeight() - $this->getAreaMargin(BOTTOM)
+ );
$this->chart->drawGraphArea(213,217,221,FALSE);
$this->chart->drawScale($this->dataSet->GetData(),$this->dataSet->GetDataDescription(),SCALE_ADDALLSTART0,213,217,221,TRUE,0,2,TRUE);
$this->chart->drawGraphAreaGradient(163,203,167,50);
@@ -55,13 +60,23 @@ class PMA_pChart_stacked extends PMA_pChart_Chart
$this->chart->drawStackedBarGraph($this->dataSet->GetData(),$this->dataSet->GetDataDescription(),70);
// Draw the title
- $this->chart->drawTextBox(0,0,$this->width,$this->labelHeight,$this->titleText,0,255,255,255,ALIGN_CENTER,TRUE,0,0,0,30);
+ $this->chart->drawTextBox(0,0,$this->getWidth(),$this->getLabelHeight(),$this->titleText,0,255,255,255,ALIGN_CENTER,TRUE,0,0,0,30);
// Draw the legend
- $this->chart->drawLegend($this->width - $this->areaMargins[1] - $legendSize[0] + $this->legendLeftMargin,$this->labelHeight + $this->areaMargins[0],$this->dataSet->GetDataDescription(),250,250,250,50,50,50);
+ $this->chart->drawLegend(
+ $this->getWidth() - $this->getAreaMargin(RIGHT) - $legendSize[0] + $this->getLegendMargin(LEFT),
+ $this->getLabelHeight() + $this->getAreaMargin(TOP),
+ $this->dataSet->GetDataDescription(),
+ 250,250,250,50,50,50
+ );
$this->chart->addBorder(2);
}
+
+ protected function getLegendMargin($side)
+ {
+ return $this->settings['legendLeftMargin'];
+ }
}
?>
diff --git a/tbl_chart.php b/tbl_chart.php
index daafd36ff..070da7be7 100644
--- a/tbl_chart.php
+++ b/tbl_chart.php
@@ -45,6 +45,15 @@ while ($row = PMA_DBI_fetch_assoc($result)) {
}*/
}
+// get settings if any posted
+$chartSettings = array();
+if (PMA_isValid($_REQUEST['chartSettings'], 'array')) {
+ $chartSettings = $_REQUEST['chartSettings'];
+}
+
+// get the chart and settings used to generate chart
+$chart = PMA_chart_results($data, $chartSettings);
+
/**
* Displays top menu links
* We use db links because a chart is not necessarily on a single table
@@ -59,17 +68,32 @@ $url_params['reload'] = 1;
* Displays the page
*/
?>
-
+