diff --git a/libraries/chart.lib.php b/libraries/chart.lib.php index b8213f2ad..1dfaf575c 100644 --- a/libraries/chart.lib.php +++ b/libraries/chart.lib.php @@ -1,5 +1,13 @@ + * @package phpMyAdmin + */ +/** + * + */ define('ERR_NO_GD', 0); define('ERR_NO_JSON', 1); @@ -13,15 +21,9 @@ require_once './libraries/chart/pma_pchart_single_radar.php'; require_once './libraries/chart/pma_pchart_multi_radar.php'; /** - * Chart functions used to generate various types - * of charts. - * - * @version $Id$ - * @package phpMyAdmin - */ - -/* - * Formats a chart for status page. + * Formats a chart for the status page. + * @param array $data data for the status chart + * @return string HTML and JS code for the chart */ function PMA_chart_status($data) { @@ -42,8 +44,10 @@ function PMA_chart_status($data) echo $chartCode; } -/* - * Formats a chart for profiling page. +/** + * Formats a chart for the profiling page. + * @param array $data data for the status chart + * @return string HTML and JS code for the chart */ function PMA_chart_profiling($data) { @@ -63,8 +67,11 @@ function PMA_chart_profiling($data) echo $chartCode; } -/* - * Formats a chart for query results page. +/** + * Formats a chart for the query results page. + * @param array $data data for the status chart + * @param array $chartSettings settings used to generate the chart + * @return string HTML and JS code for the chart */ function PMA_chart_results($data, &$chartSettings) { @@ -232,8 +239,9 @@ function PMA_chart_results($data, &$chartSettings) return $chartCode; } -/* +/** * Simple handler of chart errors. + * @param array $errors all occured errors */ function PMA_handle_chart_err($errors) { diff --git a/libraries/chart/pma_chart.php b/libraries/chart/pma_chart.php index 232a98e05..f70837f39 100644 --- a/libraries/chart/pma_chart.php +++ b/libraries/chart/pma_chart.php @@ -1,29 +1,37 @@ + * @package phpMyAdmin + */ +/** + * + */ define('RED', 0); define('GREEN', 1); define('BLUE', 2); -class PMA_Chart +/** + * The base class that all charts inherit from. + * @abstract + * @package phpMyAdmin + */ +abstract class PMA_chart { - /* - * The settings array. All the default values are here. + /** + * @var array All the default settigs values are here. */ protected $settings = array( - /* - * Default title for every chart. - */ + // Default title for every chart. 'titleText' => 'Chart', - /* - * The style of the chart title. - */ - 'titleStyle' => 'font-size: 12px; font-weight: bold;', + // The style of the chart title. + 'titleColor' => '#FAFAFA', - /* - * Colors for the different slices in the pie chart. - */ + // Colors for the different slices in the pie chart. 'colors' => array( '#BCE02E', '#E0642E', @@ -45,53 +53,50 @@ class PMA_Chart '#87C9BF', ), - /* - * Chart background color. - */ + // Chart background color. 'bgColor' => '#84AD83', - /* - * The width of the chart. - */ + // The width of the chart. 'width' => 520, - /* - * The height of the chart. - */ + // The height of the chart. 'height' => 325, - /* - * Default X Axis label. If empty, label will be taken from the data. - */ + // Default X Axis label. If empty, label will be taken from the data. 'xLabel' => '', - /* - * Default Y Axis label. If empty, label will be taken from the data. - */ + // Default Y Axis label. If empty, label will be taken from the data. 'yLabel' => '', ); - /* - * Options that the user has specified + /** + * @var array Options that the user has specified */ private $userSpecifiedSettings = null; - /* - * Error codes will be stored here + /** + * @var array Error codes will be stored here */ protected $errors = array(); + /** + * Store user specified options + * @param array $options users specified options + */ function __construct($options = null) { $this->userSpecifiedSettings = $options; } + /** + * All the variable initialization has to be done here. + */ 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. */ @@ -109,9 +114,9 @@ class PMA_Chart return $this->settings['titleText']; } - protected function getTitleStyle() + protected function getTitleColor($component) { - return $this->settings['titleStyle']; + return $this->hexStrToDecComp($this->settings['titleColor'], $component); } protected function getColors() @@ -131,7 +136,7 @@ class PMA_Chart protected function getBgColor($component) { - return hexdec(substr($this->settings['bgColor'], ($component * 2) + 1, 2)); + return $this->hexStrToDecComp($this->settings['bgColor'], $component); } protected function setXLabel($label) @@ -163,6 +168,16 @@ class PMA_Chart { return $this->errors; } + + /** + * Get one the dec color component from the hex color string + * @param string $colorString color string, i.e. #5F22A99 + * @param int $component color component to get, i.e. 0 gets red. + */ + protected function hexStrToDecComp($colorString, $component) + { + return hexdec(substr($colorString, ($component * 2) + 1, 2)); + } } ?> diff --git a/libraries/chart/pma_pchart_chart.php b/libraries/chart/pma_pchart_chart.php index bcca2ac28..3e8997030 100644 --- a/libraries/chart/pma_pchart_chart.php +++ b/libraries/chart/pma_pchart_chart.php @@ -1,5 +1,14 @@ + * @package phpMyAdmin + */ +/** + * + */ define('TOP', 0); define('RIGHT', 1); define('BOTTOM', 2); @@ -10,17 +19,36 @@ require_once 'pma_chart.php'; require_once 'pChart/pData.class'; require_once 'pChart/pChart.class'; -/* +/** * Base class for every chart implemented using pChart. + * @abstract + * @package phpMyAdmin */ -abstract class PMA_pChart_Chart extends PMA_Chart +abstract class PMA_pChart_chart extends PMA_chart { + /** + * @var String title text + */ protected $titleText; + + /** + * @var array data for the chart + */ protected $data; + /** + * @var object pData object that holds the description of the data + */ protected $dataSet; + + /** + * @var object pChart object that holds the chart + */ protected $chart; + /** + * @var array holds base64 encoded chart image parts + */ protected $partsEncoded = array(); public function __construct($data, $options = null) @@ -41,6 +69,21 @@ abstract class PMA_pChart_Chart extends PMA_Chart // as in CSS (top, right, bottom, left) $this->setAreaMargins(array(20, 20, 40, 60)); + + // when graph area gradient is used, this is the color of the graph + // area border + $this->settings['graphAreaColor'] = '#D5D9DD'; + + // the background color of the graph area + $this->settings['graphAreaGradientColor'] = '#A3CBA7'; + + // the color of the grid lines in the graph area + $this->settings['gridColor'] = '#E6E6E6'; + + // the color of the scale and the labels + $this->settings['scaleColor'] = '#D5D9DD'; + + $this->settings['titleBgColor'] = '#000000'; } protected function init() @@ -54,6 +97,7 @@ abstract class PMA_pChart_Chart extends PMA_Chart $this->dataSet = new pData; $this->chart->reportWarnings('GD'); + $this->chart->ErrorFontName = $this->getFontPath().'tahoma.ttf'; // initialize colors foreach ($this->getColors() as $key => $color) { @@ -70,14 +114,24 @@ abstract class PMA_pChart_Chart extends PMA_Chart $this->chart->setImageMap(true, 'mapid'); } + /** + * data is put to the $dataSet object according to what type chart is + * @abstract + */ abstract protected function prepareDataSet(); + /** + * all components of the chart are drawn + */ protected function prepareChart() { $this->drawBackground(); $this->drawChart(); } + /** + * draws the background + */ protected function drawBackground() { $this->drawCommon(); @@ -86,6 +140,9 @@ abstract class PMA_pChart_Chart extends PMA_Chart $this->drawGraphArea(); } + /** + * draws the part of the background which is common to most of the charts + */ protected function drawCommon() { $this->chart->drawGraphAreaGradient( @@ -96,12 +153,34 @@ abstract class PMA_pChart_Chart extends PMA_Chart $this->chart->addBorder(2); } + /** + * draws the chart title + */ protected function drawTitle() { // Draw the title - $this->chart->drawTextBox(0,0,$this->getWidth(),$this->getLabelHeight(),$this->getTitleText(),0,250,250,250,ALIGN_CENTER,True,0,0,0,30); + $this->chart->drawTextBox( + 0, + 0, + $this->getWidth(), + $this->getLabelHeight(), + $this->getTitleText(), + 0, + $this->getTitleColor(RED), + $this->getTitleColor(GREEN), + $this->getTitleColor(BLUE), + ALIGN_CENTER, + True, + $this->getTitleBgColor(RED), + $this->getTitleBgColor(GREEN), + $this->getTitleBgColor(BLUE), + 30 + ); } + /** + * calculates and sets the dimensions that will be used for the actual graph + */ protected function setGraphAreaDimensions() { $this->chart->setGraphArea( @@ -112,17 +191,49 @@ abstract class PMA_pChart_Chart extends PMA_Chart ); } + /** + * draws graph area (the area where all bars, lines, points will be seen) + */ protected function drawGraphArea() { - $this->chart->drawGraphArea(213,217,221,FALSE); - $this->chart->drawScale($this->dataSet->GetData(),$this->dataSet->GetDataDescription(),$this->getScale(),213,217,221,TRUE,0,2,TRUE); - $this->chart->drawGraphAreaGradient(163,203,167,50); - $this->chart->drawGrid(4,TRUE,230,230,230,20); + $this->chart->drawGraphArea( + $this->getGraphAreaColor(RED), + $this->getGraphAreaColor(GREEN), + $this->getGraphAreaColor(BLUE), + FALSE + ); + $this->chart->drawScale( + $this->dataSet->GetData(), + $this->dataSet->GetDataDescription(), + $this->getScale(), + $this->getScaleColor(RED), + $this->getScaleColor(GREEN), + $this->getScaleColor(BLUE), + TRUE,0,2,TRUE + ); + $this->chart->drawGraphAreaGradient( + $this->getGraphAreaGradientColor(RED), + $this->getGraphAreaGradientColor(GREEN), + $this->getGraphAreaGradientColor(BLUE), + 50 + ); + $this->chart->drawGrid( + 4, + TRUE, + $this->getGridColor(RED), + $this->getGridColor(GREEN), + $this->getGridColor(BLUE), + 20 + ); } + /** + * draws the chart + * @abstract + */ protected abstract function drawChart(); - /* + /** * Renders the chart, base 64 encodes the output and puts it into * array partsEncoded. * @@ -169,6 +280,10 @@ abstract class PMA_pChart_Chart extends PMA_Chart } } + /** + * get the HTML and JS code for the configured chart + * @return string HTML and JS code for the chart + */ public function toString() { if (!function_exists('gd_info')) { @@ -181,7 +296,9 @@ abstract class PMA_pChart_Chart extends PMA_Chart $this->prepareChart(); //$this->chart->debugImageMap(); + $this->chart->printErrors('GD'); + // check if a user wanted a chart in one part if ($this->isContinuous()) { $this->render(1); } @@ -195,6 +312,7 @@ abstract class PMA_pChart_Chart extends PMA_Chart } $returnData .= ''; + // add tooltips only if json is available if (function_exists('json_encode')) { $returnData .= '