fixed option hendling

This commit is contained in:
Martynas Mickevicius
2010-07-08 19:52:38 +03:00
parent f53b1a5294
commit 45e740e96b
4 changed files with 29 additions and 21 deletions

View File

@@ -35,7 +35,7 @@ function PMA_chart_status($data)
//$chart = new PMA_OFC_Pie(__('Query type'), $chartData, $options); //$chart = new PMA_OFC_Pie(__('Query type'), $chartData, $options);
$chart = new PMA_pChart_Pie( $chart = new PMA_pChart_Pie(
__('Query statistics'), __('Query statistics'),
$chartData); array_slice($chartData, 0, 20, true));
echo $chart->toString(); echo $chart->toString();
} }
@@ -203,8 +203,9 @@ function PMA_chart_results($data, &$chartSettings)
return __('Unknown data format.'); return __('Unknown data format.');
} }
$chartCode = $chart->toString();
$chartSettings = $chart->getSettings(); $chartSettings = $chart->getSettings();
return $chart->toString(); return $chartCode;
} }
?> ?>

View File

@@ -66,63 +66,70 @@ class PMA_Chart
'yLabel' => '', 'yLabel' => '',
); );
/*
* Options that the user has specified
*/
private $userSpecifiedSettings = null;
function __construct($options = null) function __construct($options = null)
{ {
$this->handleOptions($options); $this->userSpecifiedSettings = $options;
}
protected function init()
{
$this->handleOptions();
} }
/* /*
* A function which handles passed parameters. Useful if desired * A function which handles passed parameters. Useful if desired
* chart needs to be a little bit different from the default one. * chart needs to be a little bit different from the default one.
*
* Option handling could be made more efficient if options would be
* stored in an array.
*/ */
function handleOptions($options) private function handleOptions()
{ {
if (is_null($options)) { if (is_null($this->userSpecifiedSettings)) {
return; return;
} }
$this->settings = array_merge($this->settings, $options); $this->settings = array_merge($this->settings, $this->userSpecifiedSettings);
} }
function getTitleStyle() protected function getTitleStyle()
{ {
return $this->settings['titleStyle']; return $this->settings['titleStyle'];
} }
function getColors() protected function getColors()
{ {
return $this->settings['colors']; return $this->settings['colors'];
} }
function getWidth() protected function getWidth()
{ {
return $this->settings['width']; return $this->settings['width'];
} }
function getHeight() protected function getHeight()
{ {
return $this->settings['height']; return $this->settings['height'];
} }
function getBgColor($component) protected function getBgColor($component)
{ {
return hexdec(substr($this->settings['bgColor'], ($component * 2) + 1, 2)); return hexdec(substr($this->settings['bgColor'], ($component * 2) + 1, 2));
} }
function getXLabel() protected function getXLabel()
{ {
return $this->settings['xLabel']; return $this->settings['xLabel'];
} }
function getYLabel() protected function getYLabel()
{ {
return $this->settings['yLabel']; return $this->settings['yLabel'];
} }
function getSettings() public function getSettings()
{ {
return $this->settings; return $this->settings;
} }

View File

@@ -42,6 +42,8 @@ abstract class PMA_pChart_Chart extends PMA_Chart
protected function init() protected function init()
{ {
parent::init();
// create pChart object // create pChart object
$this->chart = new pChart($this->getWidth(), $this->getHeight()); $this->chart = new pChart($this->getWidth(), $this->getHeight());
@@ -145,9 +147,7 @@ abstract class PMA_pChart_Chart extends PMA_Chart
protected function setAreaMargins($areaMargins) protected function setAreaMargins($areaMargins)
{ {
if (!isset($this->settings['areaMargins'])) { $this->settings['areaMargins'] = $areaMargins;
$this->settings['areaMargins'] = $areaMargins;
}
} }
protected function getAreaMargin($side) protected function getAreaMargin($side)

View File

@@ -8,7 +8,7 @@ class PMA_pChart_Pie extends PMA_pChart_multi
{ {
parent::__construct($titleText, $data, $options); parent::__construct($titleText, $data, $options);
$this->setAreaMargins(array(20, 20, 20, 10)); $this->setAreaMargins(array(20, 10, 20, 20));
} }
protected function prepareDataSet() protected function prepareDataSet()