Chart title has been put to the settings array.

This commit is contained in:
Martynas Mickevicius
2010-07-09 16:27:25 +03:00
parent e5c8b5a894
commit 6b806f2047
14 changed files with 51 additions and 43 deletions

View File

@@ -32,10 +32,10 @@ function PMA_chart_status($data)
$chartData[$key] = $value; $chartData[$key] = $value;
} }
//$chart = new PMA_OFC_Pie(__('Query type'), $chartData, $options);
$chart = new PMA_pChart_Pie( $chart = new PMA_pChart_Pie(
__('Query statistics'), array_slice($chartData, 0, 18, true),
array_slice($chartData, 0, 18, true)); array('titleText' => __('Query statistics'))
);
$chartCode = $chart->toString(); $chartCode = $chart->toString();
PMA_handle_chart_err($chart->getErrors()); PMA_handle_chart_err($chart->getErrors());
echo $chartCode; echo $chartCode;
@@ -54,8 +54,9 @@ function PMA_chart_profiling($data)
} }
$chart = new PMA_pChart_Pie( $chart = new PMA_pChart_Pie(
__('Query execution time comparison (in microseconds)'), array_slice($chartData, 0, 18, true),
array_slice($chartData, 0, 18, true)); array('titleText' => __('Query execution time comparison (in microseconds)'))
);
$chartCode = $chart->toString(); $chartCode = $chart->toString();
PMA_handle_chart_err($chart->getErrors()); PMA_handle_chart_err($chart->getErrors());
echo $chartCode; echo $chartCode;
@@ -70,11 +71,8 @@ function PMA_chart_results($data, &$chartSettings)
$chart = null; $chart = null;
// set default title if not already set // set default title if not already set
if (!empty($chartSettings['title'])) { if (empty($chartSettings['titleText'])) {
$chartTitle = $chartSettings['title']; $chartSettings['titleText'] = __('Query results');
}
else {
$chartTitle = __('Query results');
} }
// set default type if not already set // set default type if not already set
@@ -111,7 +109,7 @@ function PMA_chart_results($data, &$chartSettings)
} }
$chartSettings['legend'] = true; $chartSettings['legend'] = true;
$chart = new PMA_pChart_pie($chartTitle, $chartData, $chartSettings); $chart = new PMA_pChart_pie($chartData, $chartSettings);
} }
else { else {
// loop through the rows // loop through the rows
@@ -125,13 +123,13 @@ function PMA_chart_results($data, &$chartSettings)
switch ($chartSettings['type']) { switch ($chartSettings['type']) {
case 'bar': case 'bar':
default: default:
$chart = new PMA_pChart_single_bar($chartTitle, $chartData, $chartSettings); $chart = new PMA_pChart_single_bar($chartData, $chartSettings);
break; break;
case 'line': case 'line':
$chart = new PMA_pChart_single_line($chartTitle, $chartData, $chartSettings); $chart = new PMA_pChart_single_line($chartData, $chartSettings);
break; break;
case 'radar': case 'radar':
$chart = new PMA_pChart_single_radar($chartTitle, $chartData, $chartSettings); $chart = new PMA_pChart_single_radar($chartData, $chartSettings);
break; break;
} }
} }
@@ -186,19 +184,19 @@ function PMA_chart_results($data, &$chartSettings)
switch ($chartSettings['barType']) { switch ($chartSettings['barType']) {
case 'stacked': case 'stacked':
default: default:
$chart = new PMA_pChart_stacked_bar($chartTitle, $chartData, $chartSettings); $chart = new PMA_pChart_stacked_bar($chartData, $chartSettings);
break; break;
case 'multi': case 'multi':
$chart = new PMA_pChart_multi_bar($chartTitle, $chartData, $chartSettings); $chart = new PMA_pChart_multi_bar($chartData, $chartSettings);
break; break;
} }
break; break;
case 'line': case 'line':
$chart = new PMA_pChart_multi_line($chartTitle, $chartData, $chartSettings); $chart = new PMA_pChart_multi_line($chartData, $chartSettings);
break; break;
case 'radar': case 'radar':
$chart = new PMA_pChart_multi_radar($chartTitle, $chartData, $chartSettings); $chart = new PMA_pChart_multi_radar($chartData, $chartSettings);
break; break;
} }
} }

View File

@@ -10,6 +10,12 @@ class PMA_Chart
* The settings array. All the default values are here. * The settings array. All the default values are here.
*/ */
protected $settings = array( protected $settings = array(
/*
* Default title for every chart.
*/
'titleText' => 'Chart',
/* /*
* The style of the chart title. * The style of the chart title.
*/ */
@@ -98,6 +104,11 @@ class PMA_Chart
$this->settings = array_merge($this->settings, $this->userSpecifiedSettings); $this->settings = array_merge($this->settings, $this->userSpecifiedSettings);
} }
protected function getTitleText()
{
return $this->settings['titleText'];
}
protected function getTitleStyle() protected function getTitleStyle()
{ {
return $this->settings['titleStyle']; return $this->settings['titleStyle'];

View File

@@ -23,11 +23,10 @@ abstract class PMA_pChart_Chart extends PMA_Chart
protected $imageEncoded; protected $imageEncoded;
public function __construct($titleText, $data, $options = null) public function __construct($data, $options = null)
{ {
parent::__construct($options); parent::__construct($options);
$this->titleText = $titleText;
$this->data = $data; $this->data = $data;
$this->settings['fontPath'] = './libraries/chart/pChart/fonts/'; $this->settings['fontPath'] = './libraries/chart/pChart/fonts/';
@@ -92,7 +91,7 @@ abstract class PMA_pChart_Chart extends PMA_Chart
protected function drawTitle() protected function drawTitle()
{ {
// Draw the title // Draw the title
$this->chart->drawTextBox(0,0,$this->getWidth(),$this->getLabelHeight(),$this->titleText,0,255,255,255,ALIGN_CENTER,TRUE,0,0,0,30); $this->chart->drawTextBox(0,0,$this->getWidth(),$this->getLabelHeight(),$this->getTitleText(),0,255,255,255,ALIGN_CENTER,TRUE,0,0,0,30);
} }
protected function setGraphAreaDimensions() protected function setGraphAreaDimensions()

View File

@@ -8,9 +8,9 @@ require_once 'pma_pchart_chart.php';
*/ */
abstract class PMA_pChart_multi extends PMA_pChart_chart abstract class PMA_pChart_multi extends PMA_pChart_chart
{ {
public function __construct($titleText, $data, $options = null) public function __construct($data, $options = null)
{ {
parent::__construct($titleText, $data, $options); parent::__construct($data, $options);
// as in CSS (top, right, bottom, left) // as in CSS (top, right, bottom, left)
$this->setLegendMargins(array(20, 10, 0, 0)); $this->setLegendMargins(array(20, 10, 0, 0));

View File

@@ -4,9 +4,9 @@ require_once 'pma_pchart_multi.php';
class PMA_pChart_multi_bar extends PMA_pChart_multi class PMA_pChart_multi_bar extends PMA_pChart_multi
{ {
public function __construct($titleText, $data, $options = null) public function __construct($data, $options = null)
{ {
parent::__construct($titleText, $data, $options); parent::__construct($data, $options);
$this->settings['scale'] = SCALE_NORMAL; $this->settings['scale'] = SCALE_NORMAL;
} }

View File

@@ -4,9 +4,9 @@ require_once 'pma_pchart_multi.php';
class PMA_pChart_multi_line extends PMA_pChart_multi class PMA_pChart_multi_line extends PMA_pChart_multi
{ {
public function __construct($titleText, $data, $options = null) public function __construct($data, $options = null)
{ {
parent::__construct($titleText, $data, $options); parent::__construct($data, $options);
$this->settings['scale'] = SCALE_NORMAL; $this->settings['scale'] = SCALE_NORMAL;
} }

View File

@@ -4,9 +4,9 @@ require_once 'pma_pchart_multi.php';
class PMA_pChart_multi_radar extends PMA_pChart_multi class PMA_pChart_multi_radar extends PMA_pChart_multi
{ {
public function __construct($titleText, $data, $options = null) public function __construct($data, $options = null)
{ {
parent::__construct($titleText, $data, $options); parent::__construct($data, $options);
$this->normalizeValues(); $this->normalizeValues();
} }

View File

@@ -4,9 +4,9 @@ require_once 'pma_pchart_multi.php';
class PMA_pChart_Pie extends PMA_pChart_multi class PMA_pChart_Pie extends PMA_pChart_multi
{ {
public function __construct($titleText, $data, $options = null) public function __construct($data, $options = null)
{ {
parent::__construct($titleText, $data, $options); parent::__construct($data, $options);
$this->setAreaMargins(array(20, 10, 20, 20)); $this->setAreaMargins(array(20, 10, 20, 20));
} }

View File

@@ -7,9 +7,9 @@ require_once 'pma_pchart_chart.php';
*/ */
abstract class PMA_pChart_single extends PMA_pChart_chart abstract class PMA_pChart_single extends PMA_pChart_chart
{ {
public function __construct($titleText, $data, $options = null) public function __construct($data, $options = null)
{ {
parent::__construct($titleText, $data, $options); parent::__construct($data, $options);
} }
protected function prepareDataSet() protected function prepareDataSet()

View File

@@ -4,9 +4,9 @@ require_once 'pma_pchart_single.php';
class PMA_pChart_single_bar extends PMA_pChart_single class PMA_pChart_single_bar extends PMA_pChart_single
{ {
public function __construct($titleText, $data, $options = null) public function __construct($data, $options = null)
{ {
parent::__construct($titleText, $data, $options); parent::__construct($data, $options);
} }
protected function drawChart() protected function drawChart()

View File

@@ -4,9 +4,9 @@ require_once 'pma_pchart_single.php';
class PMA_pChart_single_line extends PMA_pChart_single class PMA_pChart_single_line extends PMA_pChart_single
{ {
public function __construct($titleText, $data, $options = null) public function __construct($data, $options = null)
{ {
parent::__construct($titleText, $data, $options); parent::__construct($data, $options);
} }
protected function drawChart() protected function drawChart()

View File

@@ -4,9 +4,9 @@ require_once 'pma_pchart_single.php';
class PMA_pChart_single_radar extends PMA_pChart_single class PMA_pChart_single_radar extends PMA_pChart_single
{ {
public function __construct($titleText, $data, $options = null) public function __construct($data, $options = null)
{ {
parent::__construct($titleText, $data, $options); parent::__construct($data, $options);
$this->normalizeValues(); $this->normalizeValues();
} }

View File

@@ -4,9 +4,9 @@ require_once 'pma_pchart_multi.php';
class PMA_pChart_stacked_bar extends PMA_pChart_multi class PMA_pChart_stacked_bar extends PMA_pChart_multi
{ {
public function __construct($titleText, $data, $options = null) public function __construct($data, $options = null)
{ {
parent::__construct($titleText, $data, $options); parent::__construct($data, $options);
} }
protected function drawChart() protected function drawChart()

View File

@@ -87,8 +87,8 @@ $url_params['reload'] = 1;
<td><input type="text" name="chartSettings[height]" id="height" value="<?php echo $chartSettings['height']; ?>" /></td> <td><input type="text" name="chartSettings[height]" id="height" value="<?php echo $chartSettings['height']; ?>" /></td>
</tr> </tr>
<tr><td><label for="title"><?php echo __("Title"); ?></label></td> <tr><td><label for="titleText"><?php echo __("Title"); ?></label></td>
<td><input type="text" name="chartSettings[title]" id="title" value="<?php echo $chartSettings['title']; ?>" /></td> <td><input type="text" name="chartSettings[titleText]" id="titleText" value="<?php echo $chartSettings['titleText']; ?>" /></td>
</tr> </tr>
<?php if ($chartSettings['type'] != 'pie' && $chartSettings['type'] != 'radar') { ?> <?php if ($chartSettings['type'] != 'pie' && $chartSettings['type'] != 'radar') { ?>