Moved settings to an array. Form fields to choose settings for query result chart.
This commit is contained in:
@@ -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();
|
||||
}
|
||||
|
||||
?>
|
||||
|
@@ -2,15 +2,19 @@
|
||||
|
||||
class PMA_Chart
|
||||
{
|
||||
/*
|
||||
* The settings array. All the default values are here.
|
||||
*/
|
||||
protected $settings = array(
|
||||
/*
|
||||
* The style of the chart title.
|
||||
*/
|
||||
protected $titleStyle = 'font-size: 12px; font-weight: bold;';
|
||||
'titleStyle' => 'font-size: 12px; font-weight: bold;',
|
||||
|
||||
/*
|
||||
* Colors for the different slices in the pie chart.
|
||||
*/
|
||||
protected $colors = array(
|
||||
'colors' => array(
|
||||
'#BCE02E',
|
||||
'#E0642E',
|
||||
'#E0D62E',
|
||||
@@ -30,22 +34,23 @@ class PMA_Chart
|
||||
'#4C489B',
|
||||
'#1D674A',
|
||||
'#87C9BF',
|
||||
);
|
||||
),
|
||||
|
||||
/*
|
||||
* Chart background color.
|
||||
*/
|
||||
protected $bgColor = '#E5E5E5';
|
||||
'bgColor' => '#E5E5E5',
|
||||
|
||||
/*
|
||||
* The width of the chart.
|
||||
*/
|
||||
protected $width = 520;
|
||||
'width' => 520,
|
||||
|
||||
/*
|
||||
* The height of the chart.
|
||||
*/
|
||||
protected $height = 325;
|
||||
'height' => 325,
|
||||
);
|
||||
|
||||
function __construct($options = null)
|
||||
{
|
||||
@@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
|
@@ -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);
|
||||
|
||||
$this->settings['labelHeight'] = 20;
|
||||
|
||||
// as in CSS (top, right, bottom, left)
|
||||
private $areaMargins = array(20, 20, 40, 60);
|
||||
$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];
|
||||
}
|
||||
}
|
||||
|
||||
?>
|
||||
|
@@ -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 '<img id="pChartPicture1" src="data:image/png;base64,'.$this->imageEncoded.'" />';
|
||||
}
|
||||
|
||||
protected function getFontPath()
|
||||
{
|
||||
return $this->settings['fontPath'];
|
||||
}
|
||||
}
|
||||
|
||||
?>
|
||||
|
@@ -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'];
|
||||
}
|
||||
}
|
||||
|
||||
?>
|
||||
|
@@ -1,15 +1,15 @@
|
||||
<?php
|
||||
|
||||
require_once 'pma_pchart_chart.php';
|
||||
require_once 'pma_pchart_bar.php';
|
||||
|
||||
class PMA_pChart_stacked extends PMA_pChart_Chart
|
||||
class PMA_pChart_stacked extends PMA_pChart_bar
|
||||
{
|
||||
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);
|
||||
|
||||
private $legendLeftMargin = 10;
|
||||
$this->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'];
|
||||
}
|
||||
}
|
||||
|
||||
?>
|
||||
|
@@ -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
|
||||
*/
|
||||
?>
|
||||
<!-- CREATE VIEW options -->
|
||||
<!-- Display Chart options -->
|
||||
<div id="div_view_options">
|
||||
<form method="post" action="view_create.php">
|
||||
<form method="post" action="tbl_chart.php">
|
||||
<?php echo PMA_generate_common_hidden_inputs($url_params); ?>
|
||||
<fieldset>
|
||||
<legend><?php echo __('Display chart'); ?></legend>
|
||||
<?php echo PMA_chart_results($data); ?>
|
||||
|
||||
<div style="float: right">
|
||||
<?php echo $chart; ?>
|
||||
</div>
|
||||
|
||||
<input type="hidden" name="sql_query" id="sql_query" value="<?php echo $sql_query; ?>" />
|
||||
|
||||
<table>
|
||||
<tr><td><label for="width"><?php echo __("Width"); ?></label></td>
|
||||
<td><input type="text" name="chartSettings[width]" id="width" value="<?php echo $chartSettings['width']; ?>" /></td>
|
||||
</tr>
|
||||
|
||||
<tr><td><label for="height"><?php echo __("Height"); ?></label></td>
|
||||
<td><input type="text" name="chartSettings[height]" id="height" value="<?php echo $chartSettings['height']; ?>" /></td>
|
||||
</tr>
|
||||
</table>
|
||||
|
||||
</fieldset>
|
||||
<fieldset class="tblFooters">
|
||||
<input type="submit" name="displayChart" value="<?php echo __('Go'); ?>" />
|
||||
<input type="submit" name="displayChart" value="<?php echo __('Redraw'); ?>" />
|
||||
</fieldset>
|
||||
</form>
|
||||
</div>
|
||||
|
Reference in New Issue
Block a user