From d814efcfb634d8ddb25d5089d84583c4424bba1a Mon Sep 17 00:00:00 2001 From: Martynas Mickevicius Date: Tue, 15 Jun 2010 20:13:34 +0300 Subject: [PATCH] added the chart in the profiling window --- libraries/chart.lib.php | 4 +-- libraries/chart/pma_chart.php | 47 ++++++++++++++++++++++----------- libraries/chart/pma_ofc_pie.php | 6 +++-- libraries/common.lib.php | 42 ++++++++++++++++++++++++++++- sql.php | 2 +- 5 files changed, 79 insertions(+), 22 deletions(-) diff --git a/libraries/chart.lib.php b/libraries/chart.lib.php index 043d394a2..bf3b2c699 100644 --- a/libraries/chart.lib.php +++ b/libraries/chart.lib.php @@ -7,11 +7,11 @@ * @package phpMyAdmin */ -function PMA_chart_pie($titleText, $data) +function PMA_chart_pie($titleText, $data, $options = null) { require_once('./libraries/chart/pma_ofc_pie.php'); - $chart = new PMA_OFC_Pie($titleText, $data); + $chart = new PMA_OFC_Pie($titleText, $data, $options); echo $chart->toString(); } diff --git a/libraries/chart/pma_chart.php b/libraries/chart/pma_chart.php index 57fde5844..a1d798070 100644 --- a/libraries/chart/pma_chart.php +++ b/libraries/chart/pma_chart.php @@ -11,21 +11,21 @@ class PMA_Chart * Colors for the different slices in the pie chart. */ protected $colors = array( - '#485E70', - '#484A70', - '#594870', - '#6D4870', - '#70485E', '#70484A', '#705948', - '#706D48', - '#5E7048', - '#4A7048', + '#6D4870', + '#70485E', + '#485E70', + '#484A70', '#487059', '#48706D', - '#5F7E95', + '#594870', + '#5E7048', '#839CAF', '#95775F', + '#5F7E95', + '#706D48', + '#4A7048', '#AF9683', ); @@ -44,15 +44,30 @@ class PMA_Chart */ protected $height = 250; - /* - * Colors in the colors array have been written down in an gradient - * order. Without shuffling pie chart has an angular gradient. - * Colors could also be shuffles in the array initializer. - */ function __construct() { - shuffle(&$this->colors); + + } + + /* + * 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) + { + 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']; } } -?> \ No newline at end of file +?> diff --git a/libraries/chart/pma_ofc_pie.php b/libraries/chart/pma_ofc_pie.php index f213a2248..e8628fe06 100644 --- a/libraries/chart/pma_ofc_pie.php +++ b/libraries/chart/pma_ofc_pie.php @@ -7,10 +7,12 @@ require_once('pma_ofc_chart.php'); */ class PMA_OFC_Pie extends PMA_OFC_Chart { - function __construct($titleText, $data) + function __construct($titleText, $data, $options = null) { parent::__construct(); + $this->handleOptions($options); + include './libraries/chart/ofc/open-flash-chart.php'; // create and style chart title @@ -43,4 +45,4 @@ class PMA_OFC_Pie extends PMA_OFC_Chart } } -?> \ No newline at end of file +?> diff --git a/libraries/common.lib.php b/libraries/common.lib.php index ec2f8eb67..8002bcb48 100644 --- a/libraries/common.lib.php +++ b/libraries/common.lib.php @@ -1339,12 +1339,14 @@ function PMA_profilingCheckbox($sql_query) * Displays the results of SHOW PROFILE * * @param array the results + * @param boolean show chart * @access public * */ -function PMA_profilingResults($profiling_results) +function PMA_profilingResults($profiling_results, $show_chart = false) { echo '
' . __('Profiling') . '' . "\n"; + echo '
'; echo '' . "\n"; echo ' ' . "\n"; echo ' ' . "\n"; @@ -1356,10 +1358,48 @@ function PMA_profilingResults($profiling_results) echo '' . "\n"; echo '' . "\n"; } + echo '
' . __('Status') . '' . $one_result['Status'] . '' . $one_result['Duration'] . '
' . "\n"; + echo '
'; + + if ($show_chart) { + echo '
'; + PMA_profilingResultsChart($profiling_results); + echo '
'; + } + echo '
' . "\n"; } +/** + * Displays the results of SHOW PROFILE as a chart + * + * @param array the results + * @access public + * + */ +function PMA_profilingResultsChart($profiling_results) +{ + require_once './libraries/chart.lib.php'; + + $chart_data = array(); + foreach($profiling_results as $one_result) { + $value = (int)($one_result['Duration']*1000000); + $key = ucwords($one_result['Status']); + $chart_data[$key] = $value; + } + + echo PMA_chart_pie( + __('Query execution time comparison (in microseconds)'), + $chart_data, + array( + 'bgColor' => '#e5e5e5', + 'width' => 500, + 'height' => 300, + ) + ); +} + /** * Formats $value to byte view * diff --git a/sql.php b/sql.php index 288f150d4..1ec8f0dab 100644 --- a/sql.php +++ b/sql.php @@ -607,7 +607,7 @@ else { } if (isset($profiling_results)) { - PMA_profilingResults($profiling_results); + PMA_profilingResults($profiling_results, true); } // Displays the results in a table