From 45e740e96b8f0b042d7974d2abc617095f7cb4eb Mon Sep 17 00:00:00 2001 From: Martynas Mickevicius Date: Thu, 8 Jul 2010 19:52:38 +0300 Subject: [PATCH] fixed option hendling --- libraries/chart.lib.php | 5 ++-- libraries/chart/pma_chart.php | 37 +++++++++++++++++----------- libraries/chart/pma_pchart_chart.php | 6 ++--- libraries/chart/pma_pchart_pie.php | 2 +- 4 files changed, 29 insertions(+), 21 deletions(-) diff --git a/libraries/chart.lib.php b/libraries/chart.lib.php index 794f06cfa..6855dd12b 100644 --- a/libraries/chart.lib.php +++ b/libraries/chart.lib.php @@ -35,7 +35,7 @@ function PMA_chart_status($data) //$chart = new PMA_OFC_Pie(__('Query type'), $chartData, $options); $chart = new PMA_pChart_Pie( __('Query statistics'), - $chartData); + array_slice($chartData, 0, 20, true)); echo $chart->toString(); } @@ -203,8 +203,9 @@ function PMA_chart_results($data, &$chartSettings) return __('Unknown data format.'); } + $chartCode = $chart->toString(); $chartSettings = $chart->getSettings(); - return $chart->toString(); + return $chartCode; } ?> diff --git a/libraries/chart/pma_chart.php b/libraries/chart/pma_chart.php index d31f97f33..735b0a484 100644 --- a/libraries/chart/pma_chart.php +++ b/libraries/chart/pma_chart.php @@ -66,63 +66,70 @@ class PMA_Chart 'yLabel' => '', ); + /* + * Options that the user has specified + */ + private $userSpecifiedSettings = 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 * 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; } - $this->settings = array_merge($this->settings, $options); + $this->settings = array_merge($this->settings, $this->userSpecifiedSettings); } - function getTitleStyle() + protected function getTitleStyle() { return $this->settings['titleStyle']; } - function getColors() + protected function getColors() { return $this->settings['colors']; } - function getWidth() + protected function getWidth() { return $this->settings['width']; } - function getHeight() + protected function getHeight() { return $this->settings['height']; } - function getBgColor($component) + protected function getBgColor($component) { return hexdec(substr($this->settings['bgColor'], ($component * 2) + 1, 2)); } - function getXLabel() + protected function getXLabel() { return $this->settings['xLabel']; } - function getYLabel() + protected function getYLabel() { return $this->settings['yLabel']; } - function getSettings() + public function getSettings() { return $this->settings; } diff --git a/libraries/chart/pma_pchart_chart.php b/libraries/chart/pma_pchart_chart.php index e9485fca1..8965ee62f 100644 --- a/libraries/chart/pma_pchart_chart.php +++ b/libraries/chart/pma_pchart_chart.php @@ -42,6 +42,8 @@ abstract class PMA_pChart_Chart extends PMA_Chart protected function init() { + parent::init(); + // create pChart object $this->chart = new pChart($this->getWidth(), $this->getHeight()); @@ -145,9 +147,7 @@ abstract class PMA_pChart_Chart extends PMA_Chart protected function setAreaMargins($areaMargins) { - if (!isset($this->settings['areaMargins'])) { - $this->settings['areaMargins'] = $areaMargins; - } + $this->settings['areaMargins'] = $areaMargins; } protected function getAreaMargin($side) diff --git a/libraries/chart/pma_pchart_pie.php b/libraries/chart/pma_pchart_pie.php index 5e01d9a1a..f740dc6cd 100644 --- a/libraries/chart/pma_pchart_pie.php +++ b/libraries/chart/pma_pchart_pie.php @@ -8,7 +8,7 @@ class PMA_pChart_Pie extends PMA_pChart_multi { parent::__construct($titleText, $data, $options); - $this->setAreaMargins(array(20, 20, 20, 10)); + $this->setAreaMargins(array(20, 10, 20, 20)); } protected function prepareDataSet()