Merge branch 'blinky/master' into gsoc2010-blinky

Conflicts:
	Documentation.html - renumbered 6.28 to 6.29
This commit is contained in:
Herman van Rink
2010-08-25 16:59:54 +02:00
25 changed files with 5871 additions and 2 deletions

View File

@@ -4340,6 +4340,11 @@ chmod o+rwx tmp
other.
</p>
<h4 id="faq6_29">
<a href="#faq6_29">6.28 Why can't I get a chart from my query result table?</a></h4>
<p> Not every table can be put to the chart. Only tables with one, two or three columns can be visualised as a chart. Moreover the table must be in a special format for chart script to understand it. Currently supported formats can be found in the <a href="http://wiki.phpmyadmin.net/pma/Devel:Charts#Data_formats_for_query_results_chart">wiki</a>.</p>
<h3 id="faqproject">phpMyAdmin project</h3>
<h4 id="faq7_1">

164
js/pMap.js Normal file
View File

@@ -0,0 +1,164 @@
/**
* Holds the definition and the creation of the imageMap object
* @author Martynas Mickevicius <mmartynas@gmail.com>
* @package phpMyAdmin
*/
/**
* responsible for showing tooltips above the image chart
*/
var imageMap = {
'mouseMoved': function(event, cont) {
// return if no imageMap set
// this can happen if server has no json
if (!this.imageMap) {
return;
}
// get mouse coordinated relative to image
var mouseX = event.pageX - cont.offsetLeft;
var mouseY = event.pageY - cont.offsetTop;
//console.log("X: " + mouseX + ", Y: " + mouseY);
/* Check if we are flying over a map zone
* Lets use the following method to check if a given
* point is in any convex polygon.
* http://www.programmingforums.org/post168124-3.html
*/
var found = false;
for (var key = 0; key < this.imageMap.length; key++)
{
var seriesName = this.imageMap[key]['n'];
var seriesValue = this.imageMap[key]['v'];
var signSum = 0;
for (var i = 0; i < this.imageMap[key]['p'].length; i++)
{
var index1;
var index2;
if (i == this.imageMap[key]['p'].length - 1)
{
index1 = i;
index2 = 0;
}
else
{
index1 = i;
index2 = i+1;
}
var result = this.getDeterminant(
this.imageMap[key]['p'][index1][0],
this.imageMap[key]['p'][index1][1],
this.imageMap[key]['p'][index2][0],
this.imageMap[key]['p'][index2][1],
mouseX,
mouseY
);
if (result > 0) { signSum += 1; } else { signSum += -1; }
}
if (Math.abs(signSum) == this.imageMap[key]['p'].length)
{
found = true;
if (this.currentKey != key)
{
this.tooltip.show();
this.tooltip.title(seriesName);
this.tooltip.text(seriesValue);
this.currentKey = key;
}
this.tooltip.move(mouseX + 20, mouseY + 20);
}
}
if (!found && this.currentKey != -1 )
{
this.tooltip.hide();
this.currentKey = -1;
}
},
'getDeterminant': function (X1, Y1, X2, Y2, X3, Y3) {
return (X2*Y3 - X3*Y2) - (X1*Y3 - X3*Y1) + (X1*Y2 - X2*Y1);
},
'loadImageMap': function(map) {
this.imageMap = JSON.parse(map);
for (key in this.imageMap)
{
// FIXME
// without this loop image map does not work
// on IE8 in the status page
}
},
'init': function() {
this.tooltip.init();
$("div#chart").bind('mousemove',function(e) {
imageMap.mouseMoved(e, this);
});
this.tooltip.attach("div#chart");
this.currentKey = -1;
},
'tooltip': {
'init': function () {
this.el = $('<div></div>');
this.el.css('position', 'absolute');
this.el.css('font-family', 'tahoma');
this.el.css('background-color', '#373737');
this.el.css('color', '#BEBEBE');
this.el.css('padding', '3px');
var title = $('<p></p>');
title.attr('id', 'title');
title.css('margin', '0px');
title.css('padding', '3px');
title.css('background-color', '#606060');
title.css('text-align', 'center');
title.html('Title');
this.el.append(title);
var text = $('<p></p>');
text.attr('id', 'text');
text.css('margin', '0');
text.html('Text');
this.el.append(text);
this.hide();
},
'attach': function (element) {
$(element).prepend(this.el);
},
'move': function (x, y) {
this.el.css('margin-left', x);
this.el.css('margin-top', y);
},
'hide': function () {
this.el.css('display', 'none');
},
'show': function () {
this.el.css('display', 'block');
},
'title': function (title) {
this.el.find("p#title").html(title);
},
'text': function (text) {
this.el.find("p#text").html(text.replace(/;/g, "<br />"));
}
}
};
$(document).ready(function() {
imageMap.init();
});

256
libraries/chart.lib.php Normal file
View File

@@ -0,0 +1,256 @@
<?php
/**
* Chart functions used to generate various types of charts.
* @author Martynas Mickevicius <mmartynas@gmail.com>
* @package phpMyAdmin
*/
/**
*
*/
define('ERR_NO_GD', 0);
define('ERR_NO_JSON', 1);
require_once './libraries/chart/pma_pchart_pie.php';
require_once './libraries/chart/pma_pchart_single_bar.php';
require_once './libraries/chart/pma_pchart_multi_bar.php';
require_once './libraries/chart/pma_pchart_stacked_bar.php';
require_once './libraries/chart/pma_pchart_single_line.php';
require_once './libraries/chart/pma_pchart_multi_line.php';
require_once './libraries/chart/pma_pchart_single_radar.php';
require_once './libraries/chart/pma_pchart_multi_radar.php';
/**
* 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)
{
// format keys which will be shown in the chart
$chartData = array();
foreach($data as $dataKey => $dataValue) {
$key = ucwords(str_replace(array('Com_', '_'), array('', ' '), $dataKey));
$value = (int)$dataValue;
$chartData[$key] = $value;
}
$chart = new PMA_pChart_Pie(
$chartData,
array('titleText' => __('Query statistics'))
);
$chartCode = $chart->toString();
PMA_handle_chart_err($chart->getErrors());
echo $chartCode;
}
/**
* 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)
{
$chartData = array();
foreach($data as $dataValue) {
$value = (int)($dataValue['Duration']*1000000);
$key = ucwords($dataValue['Status']);
$chartData[$key] = $value;
}
$chart = new PMA_pChart_Pie(
$chartData,
array('titleText' => __('Query execution time comparison (in microseconds)'))
);
$chartCode = $chart->toString();
PMA_handle_chart_err($chart->getErrors());
echo $chartCode;
}
/**
* 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)
{
$chartData = array();
$chart = null;
// set default title if not already set
if (empty($chartSettings['titleText'])) {
$chartSettings['titleText'] = __('Query results');
}
// set default type if not already set
if (empty($chartSettings['type'])) {
$chartSettings['type'] = 'bar';
}
// set default type if not already set
if (empty($chartSettings['continuous'])) {
$chartSettings['continuous'] = 'off';
}
// set default bar type if needed
if ($chartSettings['type'] == 'bar' && empty($chartSettings['barType'])) {
$chartSettings['barType'] = 'stacked';
}
// default for legend
$chartSettings['legend'] = false;
// default for muti series
$chartSettings['multi'] = false;
if (!isset($data[0])) {
// empty data
return __('No data found for the chart.');
}
if (count($data[0]) == 1 || count($data[0]) == 2) {
// One or two columns in every row.
// This data is suitable for a simple bar chart.
if ($chartSettings['type'] == 'pie') {
// loop through the rows, data for pie chart has to be formated
// in a different way then in other charts.
foreach ($data as $rowKey => $row) {
$values = array_values($row);
if (count($row) == 1) {
$chartData[$rowKey] = $values[0];
}
else {
$chartData[$values[1]] = $values[0];
}
}
$chartSettings['legend'] = true;
$chart = new PMA_pChart_pie($chartData, $chartSettings);
}
else {
// loop through the rows
foreach ($data as $rowKey => $row) {
// loop through the columns in the row
foreach ($row as $valueKey => $value) {
$chartData[$valueKey][] = $value;
}
// if only one column, we need to add
// placeholder data for x axis
if (count($row) == 1) {
$chartData[''][] = $rowKey;
}
}
switch ($chartSettings['type']) {
case 'bar':
default:
$chart = new PMA_pChart_single_bar($chartData, $chartSettings);
break;
case 'line':
$chart = new PMA_pChart_single_line($chartData, $chartSettings);
break;
case 'radar':
$chart = new PMA_pChart_single_radar($chartData, $chartSettings);
break;
}
}
}
else if (count($data[0]) == 3) {
// Three columns (x axis, y axis, series) in every row.
// This data is suitable for a stacked bar chart.
$chartSettings['multi'] = true;
$keys = array_keys($data[0]);
$yAxisKey = $keys[0];
$xAxisKey = $keys[1];
$seriesKey = $keys[2];
// get all the series labels
$seriesLabels = array();
foreach ($data as $row) {
$seriesLabels[] = $row[$seriesKey];
}
$seriesLabels = array_unique($seriesLabels);
// loop through the rows
$currentXLabel = $data[0][$xAxisKey];
foreach ($data as $row) {
// save the label
// use the same value as the key and the value to get rid of duplicate results
$chartData[$xAxisKey][$row[$xAxisKey]] = $row[$xAxisKey];
// make sure to set value to every serie
$currentSeriesLabel = (string)$row[$seriesKey];
foreach ($seriesLabels as $seriesLabelsValue) {
if ($currentSeriesLabel == $seriesLabelsValue) {
// the value os for this serie
$chartData[$yAxisKey][$seriesLabelsValue][$row[$xAxisKey]] = (int)$row[$yAxisKey];
}
else if (!isset($chartData[$yAxisKey][$seriesLabelsValue][$row[$xAxisKey]])) {
// if the value for this serie is not set, set it to 0
$chartData[$yAxisKey][$seriesLabelsValue][$row[$xAxisKey]] = 0;
}
}
}
$chartSettings['legend'] = true;
// determine the chart type
switch ($chartSettings['type']) {
case 'bar':
default:
// determine the bar chart type
switch ($chartSettings['barType']) {
case 'stacked':
default:
$chart = new PMA_pChart_stacked_bar($chartData, $chartSettings);
break;
case 'multi':
$chart = new PMA_pChart_multi_bar($chartData, $chartSettings);
break;
}
break;
case 'line':
$chart = new PMA_pChart_multi_line($chartData, $chartSettings);
break;
case 'radar':
$chart = new PMA_pChart_multi_radar($chartData, $chartSettings);
break;
}
}
else {
// unknown data format
return '';
}
$chartCode = $chart->toString();
$chartSettings = $chart->getSettings();
$chartErrors = $chart->getErrors();
PMA_handle_chart_err($chartErrors);
return $chartCode;
}
/**
* Simple handler of chart errors.
* @param array $errors all occured errors
*/
function PMA_handle_chart_err($errors)
{
if (in_array(ERR_NO_GD, $errors)) {
PMA_warnMissingExtension('GD', false, 'GD extension is needed for charts.');
}
else if (in_array(ERR_NO_JSON, $errors)) {
PMA_warnMissingExtension('JSON', false, 'JSON encoder is needed for chart tooltips.');
}
}
?>

Binary file not shown.

View File

@@ -0,0 +1,119 @@
<?php
/*
pCache - Faster renderding using data cache
Copyright (C) 2008 Jean-Damien POGOLOTTI
Version 1.1.2 last updated on 06/17/08
http://pchart.sourceforge.net
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 1,2,3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
Class initialisation :
pCache($CacheFolder="Cache/")
Cache management :
IsInCache($Data)
GetFromCache($ID,$Data)
WriteToCache($ID,$Data,$Picture)
DeleteFromCache($ID,$Data)
ClearCache()
Inner functions :
GetHash($ID,$Data)
*/
/* pCache class definition */
class pCache
{
var $HashKey = "";
var $CacheFolder = "Cache/";
/* Create the pCache object */
function pCache($CacheFolder="Cache/")
{
$this->CacheFolder = $CacheFolder;
}
/* This function is clearing the cache folder */
function ClearCache()
{
if ($handle = opendir($this->CacheFolder))
{
while (false !== ($file = readdir($handle)))
{
if ( $file != "." && $file != ".." )
unlink($this->CacheFolder.$file);
}
closedir($handle);
}
}
/* This function is checking if we have an offline version of this chart */
function IsInCache($ID,$Data,$Hash="")
{
if ( $Hash == "" )
$Hash = $this->GetHash($ID,$Data);
if ( file_exists($this->CacheFolder.$Hash) )
return(TRUE);
else
return(FALSE);
}
/* This function is making a copy of drawn chart in the cache folder */
function WriteToCache($ID,$Data,$Picture)
{
$Hash = $this->GetHash($ID,$Data);
$FileName = $this->CacheFolder.$Hash;
imagepng($Picture->Picture,$FileName);
}
/* This function is removing any cached copy of this chart */
function DeleteFromCache($ID,$Data)
{
$Hash = $this->GetHash($ID,$Data);
$FileName = $this->CacheFolder.$Hash;
if ( file_exists($FileName ) )
unlink($FileName);
}
/* This function is retrieving the cached picture if applicable */
function GetFromCache($ID,$Data)
{
$Hash = $this->GetHash($ID,$Data);
if ( $this->IsInCache("","",$Hash ) )
{
$FileName = $this->CacheFolder.$Hash;
header('Content-type: image/png');
@readfile($FileName);
exit();
}
}
/* This function is building the graph unique hash key */
function GetHash($ID,$Data)
{
$mKey = "$ID";
foreach($Data as $key => $Values)
{
$tKey = "";
foreach($Values as $Serie => $Value)
$tKey = $tKey.$Serie.$Value;
$mKey = $mKey.md5($tKey);
}
return(md5($mKey));
}
}
?>

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,260 @@
<?php
/*
pData - Simplifying data population for pChart
Copyright (C) 2008 Jean-Damien POGOLOTTI
Version 1.13 last updated on 08/17/08
http://pchart.sourceforge.net
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 1,2,3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
Class initialisation :
pData()
Data populating methods :
ImportFromCSV($FileName,$Delimiter=",",$DataColumns=-1,$HasHeader=FALSE,$DataName=-1)
AddPoint($Value,$Serie="Serie1",$Description="")
Series manipulation methods :
AddSerie($SerieName="Serie1")
AddAllSeries()
RemoveSerie($SerieName="Serie1")
SetAbsciseLabelSerie($SerieName = "Name")
SetSerieName($Name,$SerieName="Serie1")
+ SetSerieSymbol($Name,$Symbol)
SetXAxisName($Name="X Axis")
SetYAxisName($Name="Y Axis")
SetXAxisFormat($Format="number")
SetYAxisFormat($Format="number")
SetXAxisUnit($Unit="")
SetYAxisUnit($Unit="")
removeSerieName($SerieName)
removeAllSeries()
Data retrieval methods :
GetData()
GetDataDescription()
*/
/* pData class definition */
class pData
{
var $Data;
var $DataDescription;
function pData()
{
$this->Data = array();
$this->DataDescription = "";
$this->DataDescription["Position"] = "Name";
$this->DataDescription["Format"]["X"] = "number";
$this->DataDescription["Format"]["Y"] = "number";
$this->DataDescription["Unit"]["X"] = NULL;
$this->DataDescription["Unit"]["Y"] = NULL;
}
function ImportFromCSV($FileName,$Delimiter=",",$DataColumns=-1,$HasHeader=FALSE,$DataName=-1)
{
$handle = @fopen($FileName,"r");
if ($handle)
{
$HeaderParsed = FALSE;
while (!feof($handle))
{
$buffer = fgets($handle, 4096);
$buffer = str_replace(chr(10),"",$buffer);
$buffer = str_replace(chr(13),"",$buffer);
$Values = split($Delimiter,$buffer);
if ( $buffer != "" )
{
if ( $HasHeader == TRUE && $HeaderParsed == FALSE )
{
if ( $DataColumns == -1 )
{
$ID = 1;
foreach($Values as $key => $Value)
{ $this->SetSerieName($Value,"Serie".$ID); $ID++; }
}
else
{
$SerieName = "";
foreach($DataColumns as $key => $Value)
$this->SetSerieName($Values[$Value],"Serie".$Value);
}
$HeaderParsed = TRUE;
}
else
{
if ( $DataColumns == -1 )
{
$ID = 1;
foreach($Values as $key => $Value)
{ $this->AddPoint(intval($Value),"Serie".$ID); $ID++; }
}
else
{
$SerieName = "";
if ( $DataName != -1 )
$SerieName = $Values[$DataName];
foreach($DataColumns as $key => $Value)
$this->AddPoint($Values[$Value],"Serie".$Value,$SerieName);
}
}
}
}
fclose($handle);
}
}
function AddPoint($Value,$Serie="Serie1",$Description="")
{
if (is_array($Value) && count($Value) == 1)
$Value = array_pop($Value);
$ID = 0;
for($i=0;$i<=count($this->Data);$i++)
{ if(isset($this->Data[$i][$Serie])) { $ID = $i+1; } }
if ( count($Value) == 1 )
{
$this->Data[$ID][$Serie] = $Value;
if ( $Description != "" )
$this->Data[$ID]["Name"] = $Description;
elseif (!isset($this->Data[$ID]["Name"]))
$this->Data[$ID]["Name"] = $ID;
}
else
{
foreach($Value as $key => $Val)
{
$this->Data[$ID][$Serie] = $Val;
if (!isset($this->Data[$ID]["Name"]))
$this->Data[$ID]["Name"] = $ID;
$ID++;
}
}
}
function AddSerie($SerieName="Serie1")
{
if ( !isset($this->DataDescription["Values"]) )
{
$this->DataDescription["Values"][] = $SerieName;
}
else
{
$Found = FALSE;
foreach($this->DataDescription["Values"] as $key => $Value )
if ( $Value == $SerieName ) { $Found = TRUE; }
if ( !$Found )
$this->DataDescription["Values"][] = $SerieName;
}
}
function AddAllSeries()
{
unset($this->DataDescription["Values"]);
if ( isset($this->Data[0]) )
{
foreach($this->Data[0] as $Key => $Value)
{
if ( $Key != "Name" )
$this->DataDescription["Values"][] = $Key;
}
}
}
function RemoveSerie($SerieName="Serie1")
{
if ( !isset($this->DataDescription["Values"]) )
return(0);
$Found = FALSE;
foreach($this->DataDescription["Values"] as $key => $Value )
{
if ( $Value == $SerieName )
unset($this->DataDescription["Values"][$key]);
}
}
function SetAbsciseLabelSerie($SerieName = "Name")
{
$this->DataDescription["Position"] = $SerieName;
}
function SetSerieName($Name,$SerieName="Serie1")
{
$this->DataDescription["Description"][$SerieName] = $Name;
}
function SetXAxisName($Name="X Axis")
{
$this->DataDescription["Axis"]["X"] = $Name;
}
function SetYAxisName($Name="Y Axis")
{
$this->DataDescription["Axis"]["Y"] = $Name;
}
function SetXAxisFormat($Format="number")
{
$this->DataDescription["Format"]["X"] = $Format;
}
function SetYAxisFormat($Format="number")
{
$this->DataDescription["Format"]["Y"] = $Format;
}
function SetXAxisUnit($Unit="")
{
$this->DataDescription["Unit"]["X"] = $Unit;
}
function SetYAxisUnit($Unit="")
{
$this->DataDescription["Unit"]["Y"] = $Unit;
}
function SetSerieSymbol($Name,$Symbol)
{
$this->DataDescription["Symbol"][$Name] = $Symbol;
}
function removeSerieName($SerieName)
{
if ( isset($this->DataDescription["Description"][$SerieName]) )
unset($this->DataDescription["Description"][$SerieName]);
}
function removeAllSeries()
{
foreach($this->DataDescription["Values"] as $Key => $Value)
unset($this->DataDescription["Values"][$Key]);
}
function GetData()
{
return($this->Data);
}
function GetDataDescription()
{
return($this->DataDescription);
}
}
?>

View File

@@ -0,0 +1,183 @@
<?php
/**
* Holds the base class that all charts inherit from and some widely used
* constants.
* @author Martynas Mickevicius <mmartynas@gmail.com>
* @package phpMyAdmin
*/
/**
*
*/
define('RED', 0);
define('GREEN', 1);
define('BLUE', 2);
/**
* The base class that all charts inherit from.
* @abstract
* @package phpMyAdmin
*/
abstract class PMA_chart
{
/**
* @var array All the default settigs values are here.
*/
protected $settings = array(
// Default title for every chart.
'titleText' => 'Chart',
// The style of the chart title.
'titleColor' => '#FAFAFA',
// Colors for the different slices in the pie chart.
'colors' => array(
'#BCE02E',
'#E0642E',
'#E0D62E',
'#2E97E0',
'#B02EE0',
'#E02E75',
'#5CE02E',
'#E0B02E',
'#000000',
'#0022E0',
'#726CB1',
'#481A36',
'#BAC658',
'#127224',
'#825119',
'#238C74',
'#4C489B',
'#87C9BF',
),
// Chart background color.
'bgColor' => '#84AD83',
// The width of the chart.
'width' => 520,
// The height of the chart.
'height' => 325,
// 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.
'yLabel' => '',
);
/**
* @var array Options that the user has specified
*/
private $userSpecifiedSettings = null;
/**
* @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.
*/
private function handleOptions()
{
if (is_null($this->userSpecifiedSettings)) {
return;
}
$this->settings = array_merge($this->settings, $this->userSpecifiedSettings);
}
protected function getTitleText()
{
return $this->settings['titleText'];
}
protected function getTitleColor($component)
{
return $this->hexStrToDecComp($this->settings['titleColor'], $component);
}
protected function getColors()
{
return $this->settings['colors'];
}
protected function getWidth()
{
return $this->settings['width'];
}
protected function getHeight()
{
return $this->settings['height'];
}
protected function getBgColor($component)
{
return $this->hexStrToDecComp($this->settings['bgColor'], $component);
}
protected function setXLabel($label)
{
$this->settings['xLabel'] = $label;
}
protected function getXLabel()
{
return $this->settings['xLabel'];
}
protected function setYLabel($label)
{
$this->settings['yLabel'] = $label;
}
protected function getYLabel()
{
return $this->settings['yLabel'];
}
public function getSettings()
{
return $this->settings;
}
public function getErrors()
{
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));
}
}
?>

View File

@@ -0,0 +1,396 @@
<?php
/**
* Holds the base class that all charts using pChart inherit from and some
* widely used constants
* @author Martynas Mickevicius <mmartynas@gmail.com>
* @package phpMyAdmin
*/
/**
*
*/
define('TOP', 0);
define('RIGHT', 1);
define('BOTTOM', 2);
define('LEFT', 3);
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
{
/**
* @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)
{
parent::__construct($options);
$this->data = $data;
$this->settings['fontPath'] = './libraries/chart/pChart/fonts/';
$this->settings['scale'] = SCALE_ADDALLSTART0;
$this->settings['labelHeight'] = 20;
$this->settings['fontSize'] = 8;
$this->settings['continuous'] = 'off';
// 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()
{
parent::init();
// create pChart object
$this->chart = new pChart($this->getWidth(), $this->getHeight());
// create pData object
$this->dataSet = new pData;
$this->chart->reportWarnings('GD');
$this->chart->ErrorFontName = $this->getFontPath().'tahoma.ttf';
// initialize colors
foreach ($this->getColors() as $key => $color) {
$this->chart->setColorPalette(
$key,
hexdec(substr($color, 1, 2)),
hexdec(substr($color, 3, 2)),
hexdec(substr($color, 5, 2))
);
}
$this->chart->setFontProperties($this->getFontPath().'tahoma.ttf', $this->getFontSize());
$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();
$this->drawTitle();
$this->setGraphAreaDimensions();
$this->drawGraphArea();
}
/**
* draws the part of the background which is common to most of the charts
*/
protected function drawCommon()
{
$this->chart->drawGraphAreaGradient(
$this->getBgColor(RED),
$this->getBgColor(GREEN),
$this->getBgColor(BLUE),
50,TARGET_BACKGROUND);
$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,
$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(
$this->getAreaMargin(LEFT),
$this->getLabelHeight() + $this->getAreaMargin(TOP),
$this->getWidth() - $this->getAreaMargin(RIGHT),
$this->getHeight() - $this->getAreaMargin(BOTTOM)
);
}
/**
* draws graph area (the area where all bars, lines, points will be seen)
*/
protected function drawGraphArea()
{
$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.
*
* Parameter can be used to slice the chart vertically into parts. This
* solves an issue where some browsers (IE8) accept base64 images only up
* to some length.
*
* @param integer $parts number of parts to render.
* Default value 1 means that all the
* chart will be in one piece.
*/
protected function render($parts = 1)
{
$fullWidth = 0;
for ($i = 0; $i < $parts; $i++) {
// slicing is vertical so part height is the full height
$partHeight = $this->chart->YSize;
// there will be some rounding erros, will compensate later
$partWidth = round($this->chart->XSize / $parts);
$fullWidth += $partWidth;
$partX = $partWidth * $i;
if ($i == $parts - 1) {
// if this is the last part, compensate for the rounding errors
$partWidth += $this->chart->XSize - $fullWidth;
}
// get a part from the full chart image
$part = imagecreatetruecolor($partWidth, $partHeight);
imagecopy($part, $this->chart->Picture, 0, 0, $partX, 0, $partWidth, $partHeight);
// render part and save it to variable
ob_start();
imagepng($part, NULL, 9, PNG_ALL_FILTERS);
$output = ob_get_contents();
ob_end_clean();
// base64 encode the current part
$partEncoded = base64_encode($output);
$this->partsEncoded[$i] = $partEncoded;
}
}
/**
* 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')) {
array_push($this->errors, ERR_NO_GD);
return '';
}
$this->init();
$this->prepareDataSet();
$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);
}
else {
$this->render(20);
}
$returnData = '<div id="chart">';
foreach ($this->partsEncoded as $part) {
$returnData .= '<img src="data:image/png;base64,'.$part.'" />';
}
$returnData .= '</div>';
// add tooltips only if json is available
if (function_exists('json_encode')) {
$returnData .= '
<script type="text/javascript">
imageMap.loadImageMap(\''.json_encode($this->getImageMap()).'\');
</script>
';
}
else {
array_push($this->errors, ERR_NO_JSON);
}
return $returnData;
}
protected function getLabelHeight()
{
return $this->settings['labelHeight'];
}
protected function setAreaMargins($areaMargins)
{
$this->settings['areaMargins'] = $areaMargins;
}
protected function getAreaMargin($side)
{
return $this->settings['areaMargins'][$side];
}
protected function getFontPath()
{
return $this->settings['fontPath'];
}
protected function getScale()
{
return $this->settings['scale'];
}
protected function getFontSize()
{
return $this->settings['fontSize'];
}
protected function isContinuous()
{
return $this->settings['continuous'] == 'on';
}
protected function getImageMap()
{
return $this->chart->getImageMap();
}
protected function getGraphAreaColor($component)
{
return $this->hexStrToDecComp($this->settings['graphAreaColor'], $component);
}
protected function getGraphAreaGradientColor($component)
{
return $this->hexStrToDecComp($this->settings['graphAreaGradientColor'], $component);
}
protected function getGridColor($component)
{
return $this->hexStrToDecComp($this->settings['gridColor'], $component);
}
protected function getScaleColor($component)
{
return $this->hexStrToDecComp($this->settings['scaleColor'], $component);
}
protected function getTitleBgColor($component)
{
return $this->hexStrToDecComp($this->settings['titleBgColor'], $component);
}
}
?>

View File

@@ -0,0 +1,117 @@
<?php
/**
* @author Martynas Mickevicius <mmartynas@gmail.com>
* @package phpMyAdmin
*/
/**
*
*/
require_once 'pma_pchart_chart.php';
/**
* Base class for every chart that uses multiple series.
* All of these charts will require legend box.
* @abstract
* @package phpMyAdmin
*/
abstract class PMA_pChart_multi extends PMA_pChart_chart
{
public function __construct($data, $options = null)
{
parent::__construct($data, $options);
// as in CSS (top, right, bottom, left)
$this->setLegendMargins(array(20, 10, 0, 0));
}
/**
* data set preparation for multi serie graphs
*/
protected function prepareDataSet()
{
$values = array_values($this->data);
$keys = array_keys($this->data);
// Dataset definition
$this->dataSet->AddPoint($values[0], "Keys");
$i = 0;
foreach ($values[1] as $seriesName => $seriesData) {
$this->dataSet->AddPoint($seriesData, "Values".$i);
$this->dataSet->SetSerieName($seriesName, "Values".$i);
$i++;
}
$this->dataSet->AddAllSeries();
$this->dataSet->RemoveSerie("Keys");
$this->dataSet->SetAbsciseLabelSerie("Keys");
$xLabel = $this->getXLabel();
if (empty($xLabel)) {
$this->setXLabel($keys[0]);
}
$yLabel = $this->getYLabel();
if (empty($yLabel)) {
$this->setYLabel($keys[1]);
}
$this->dataSet->SetXAxisName($this->getXLabel());
$this->dataSet->SetYAxisName($this->getYLabel());
}
/**
* set graph area dimensions with respect to legend box size
*/
protected function setGraphAreaDimensions()
{
$this->chart->setGraphArea(
$this->getAreaMargin(LEFT),
$this->getLabelHeight() + $this->getAreaMargin(TOP),
$this->getWidth() - $this->getAreaMargin(RIGHT) - $this->getLegendBoxWidth() - $this->getLegendMargin(LEFT) - $this->getLegendMargin(RIGHT),
$this->getHeight() - $this->getAreaMargin(BOTTOM)
);
}
/**
* multi serie charts need a legend. draw it
*/
protected function drawChart()
{
$this->drawLegend();
}
/**
* draws a legend
*/
protected function drawLegend()
{
// Draw the legend
$this->chart->drawLegend(
$this->getWidth() - $this->getLegendMargin(RIGHT) - $this->getLegendBoxWidth(),
$this->getLabelHeight() + $this->getLegendMargin(TOP),
$this->dataSet->GetDataDescription(),
250,250,250,50,50,50
);
}
protected function setLegendMargins($legendMargins)
{
if (!isset($this->settings['legendMargins'])) {
$this->settings['legendMargins'] = $legendMargins;
}
}
protected function getLegendMargin($side)
{
return $this->settings['legendMargins'][$side];
}
protected function getLegendBoxWidth()
{
$legendSize = $this->chart->getLegendBoxSize($this->dataSet->GetDataDescription());
return $legendSize[0];
}
}
?>

View File

@@ -0,0 +1,37 @@
<?php
/**
* @author Martynas Mickevicius <mmartynas@gmail.com>
* @package phpMyAdmin
*/
/**
*
*/
require_once 'pma_pchart_multi.php';
/**
* implements multi bar chart
* @package phpMyAdmin
*/
class PMA_pChart_multi_bar extends PMA_pChart_multi
{
public function __construct($data, $options = null)
{
parent::__construct($data, $options);
$this->settings['scale'] = SCALE_NORMAL;
}
/**
* draws multi bar graph
*/
protected function drawChart()
{
parent::drawChart();
// Draw the bar chart
$this->chart->drawBarGraph($this->dataSet->GetData(),$this->dataSet->GetDataDescription(),70);
}
}
?>

View File

@@ -0,0 +1,38 @@
<?php
/**
* @author Martynas Mickevicius <mmartynas@gmail.com>
* @package phpMyAdmin
*/
/**
*
*/
require_once 'pma_pchart_multi.php';
/**
* implements multi line chart
* @package phpMyAdmin
*/
class PMA_pChart_multi_line extends PMA_pChart_multi
{
public function __construct($data, $options = null)
{
parent::__construct($data, $options);
$this->settings['scale'] = SCALE_NORMAL;
}
/**
* draws multi line chart
*/
protected function drawChart()
{
parent::drawChart();
// Draw the bar chart
$this->chart->drawLineGraph($this->dataSet->GetData(),$this->dataSet->GetDataDescription());
$this->chart->drawPlotGraph($this->dataSet->GetData(),$this->dataSet->GetDataDescription(),3,1,-1,-1,-1,TRUE);
}
}
?>

View File

@@ -0,0 +1,98 @@
<?php
/**
* @author Martynas Mickevicius <mmartynas@gmail.com>
* @package phpMyAdmin
*/
/**
*
*/
require_once 'pma_pchart_multi.php';
/**
* implements multi radar chart
* @package phpMyAdmin
*/
class PMA_pChart_multi_radar extends PMA_pChart_multi
{
public function __construct($data, $options = null)
{
parent::__construct($data, $options);
$this->normalizeValues();
}
/**
* Get the largest value from the data and normalize all the other values.
*/
private function normalizeValues()
{
$maxValue = 0;
$keys = array_keys($this->data);
$valueKey = $keys[1];
// get the max value
foreach ($this->data[$valueKey] as $values) {
if (max($values) > $maxValue) {
$maxValue = max($values);
}
}
// normalize all the values according to the max value
foreach ($this->data[$valueKey] as &$values) {
foreach ($values as &$value) {
$value = $value / $maxValue * 10;
}
}
}
/**
* graph area for the radar chart does not include grid lines
*/
protected function drawGraphArea()
{
$this->chart->drawGraphArea(
$this->getGraphAreaColor(RED),
$this->getGraphAreaColor(GREEN),
$this->getGraphAreaColor(BLUE),
FALSE
);
$this->chart->drawGraphAreaGradient(
$this->getGraphAreaGradientColor(RED),
$this->getGraphAreaGradientColor(GREEN),
$this->getGraphAreaGradientColor(BLUE),
50
);
}
/**
* draw multi radar chart
*/
protected function drawChart()
{
parent::drawChart();
// when drawing radar graph we can specify the border from the top of
// graph area. We want border to be dynamic, so that either the top
// or the side of the radar is some distance away from the top or the
// side of the graph area.
$areaWidth = $this->chart->GArea_X2 - $this->chart->GArea_X1;
$areaHeight = $this->chart->GArea_Y2 - $this->chart->GArea_Y1;
if ($areaHeight > $areaWidth) {
$borderOffset = ($areaHeight - $areaWidth) / 2;
}
else {
$borderOffset = 0;
}
// the least ammount that radar is away from the graph area side.
$borderOffset += 40;
// Draw the radar chart
$this->chart->drawRadarAxis($this->dataSet->GetData(),$this->dataSet->GetDataDescription(),TRUE,$borderOffset,120,120,120,230,230,230,-1,2);
$this->chart->drawFilledRadar($this->dataSet->GetData(),$this->dataSet->GetDataDescription(),50,$borderOffset);
}
}
?>

View File

@@ -0,0 +1,100 @@
<?php
/**
* @author Martynas Mickevicius <mmartynas@gmail.com>
* @package phpMyAdmin
*/
/**
*
*/
require_once 'pma_pchart_multi.php';
/**
* implements pie chart
* @package phpMyAdmin
*/
class PMA_pChart_Pie extends PMA_pChart_multi
{
public function __construct($data, $options = null)
{
// limit data size, no more than 18 pie slices
$data = array_slice($data, 0, 18, true);
parent::__construct($data, $options);
$this->setAreaMargins(array(20, 10, 20, 20));
}
/**
* prepare data set for the pie chart
*/
protected function prepareDataSet()
{
// Dataset definition
$this->dataSet->AddPoint(array_values($this->data),"Values");
$this->dataSet->AddPoint(array_keys($this->data),"Keys");
$this->dataSet->AddAllSeries();
$this->dataSet->SetAbsciseLabelSerie("Keys");
}
/**
* graph area for the pie chart does not include grid lines
*/
protected function drawGraphArea()
{
$this->chart->drawGraphArea(
$this->getGraphAreaColor(RED),
$this->getGraphAreaColor(GREEN),
$this->getGraphAreaColor(BLUE),
FALSE
);
$this->chart->drawGraphAreaGradient(
$this->getGraphAreaGradientColor(RED),
$this->getGraphAreaGradientColor(GREEN),
$this->getGraphAreaGradientColor(BLUE),
50
);
}
/**
* draw the pie chart
*/
protected function drawChart()
{
parent::drawChart();
// draw pie chart in the middle of graph area
$middleX = ($this->chart->GArea_X1 + $this->chart->GArea_X2) / 2;
$middleY = ($this->chart->GArea_Y1 + $this->chart->GArea_Y2) / 2;
$this->chart->drawPieGraph(
$this->dataSet->GetData(),
$this->dataSet->GetDataDescription(),
$middleX,
// pie graph is skewed. Upper part is shorter than the
// lower part. This is why we set an offset to the
// Y middle coordiantes.
$middleY - 15,
120,PIE_PERCENTAGE,FALSE,60,30,10,1);
}
/**
* draw legend for the pie chart
*/
protected function drawLegend()
{
$this->chart->drawPieLegend(
$this->getWidth() - $this->getLegendMargin(RIGHT) - $this->getLegendBoxWidth(),
$this->getLabelHeight() + $this->getLegendMargin(TOP),
$this->dataSet->GetData(),
$this->dataSet->GetDataDescription(),
250,250,250);
}
protected function getLegendBoxWidth()
{
$legendSize = $this->chart->getPieLegendBoxSize($this->dataSet->GetData());
return $legendSize[0];
}
}
?>

View File

@@ -0,0 +1,56 @@
<?php
/**
* @author Martynas Mickevicius <mmartynas@gmail.com>
* @package phpMyAdmin
*/
/**
*
*/
require_once 'pma_pchart_chart.php';
/**
* Base class for every chart that uses only one series.
* @abstract
* @package phpMyAdmin
*/
abstract class PMA_pChart_single extends PMA_pChart_chart
{
public function __construct($data, $options = null)
{
parent::__construct($data, $options);
}
/**
* data set preparation for single serie charts
*/
protected function prepareDataSet()
{
$values = array_values($this->data);
$keys = array_keys($this->data);
// Dataset definition
$this->dataSet->AddPoint($values[0], "Values");
$this->dataSet->AddPoint($values[1], "Keys");
//$this->dataSet->AddAllSeries();
$this->dataSet->AddSerie("Values");
$this->dataSet->SetAbsciseLabelSerie("Keys");
$yLabel = $this->getYLabel();
if (empty($yLabel)) {
$this->setYLabel($keys[0]);
}
$xLabel = $this->getXLabel();
if (empty($xLabel)) {
$this->setXLabel($keys[1]);
}
$this->dataSet->SetXAxisName($this->getXLabel());
$this->dataSet->SetYAxisName($this->getYLabel());
$this->dataSet->SetSerieName($this->getYLabel(), "Values");
}
}
?>

View File

@@ -0,0 +1,34 @@
<?php
/**
* @author Martynas Mickevicius <mmartynas@gmail.com>
* @package phpMyAdmin
*/
/**
*
*/
require_once 'pma_pchart_single.php';
/**
* implements single bar chart
* @package phpMyAdmin
*/
class PMA_pChart_single_bar extends PMA_pChart_single
{
public function __construct($data, $options = null)
{
parent::__construct($data, $options);
}
/**
* draws single bar chart
*/
protected function drawChart()
{
// Draw the bar chart
// use stacked bar graph function, because it gives bars with alpha
$this->chart->drawStackedBarGraph($this->dataSet->GetData(),$this->dataSet->GetDataDescription(),70);
}
}
?>

View File

@@ -0,0 +1,34 @@
<?php
/**
* @author Martynas Mickevicius <mmartynas@gmail.com>
* @package phpMyAdmin
*/
/**
*
*/
require_once 'pma_pchart_single.php';
/**
* implements single line chart
* @package phpMyAdmin
*/
class PMA_pChart_single_line extends PMA_pChart_single
{
public function __construct($data, $options = null)
{
parent::__construct($data, $options);
}
/**
* draws single line chart
*/
protected function drawChart()
{
// Draw the line chart
$this->chart->drawLineGraph($this->dataSet->GetData(),$this->dataSet->GetDataDescription());
$this->chart->drawPlotGraph($this->dataSet->GetData(),$this->dataSet->GetDataDescription(),3,1,-1,-1,-1,TRUE);
}
}
?>

View File

@@ -0,0 +1,86 @@
<?php
/**
* @author Martynas Mickevicius <mmartynas@gmail.com>
* @package phpMyAdmin
*/
/**
*
*/
require_once 'pma_pchart_single.php';
/**
* implements single radar chart
* @package phpMyAdmin
*/
class PMA_pChart_single_radar extends PMA_pChart_single
{
public function __construct($data, $options = null)
{
parent::__construct($data, $options);
$this->normalizeValues();
}
/**
* Get the largest value from the data and normalize all the other values.
*/
private function normalizeValues()
{
$maxValue = 0;
$keys = array_keys($this->data);
$valueKey = $keys[0];
$maxValue = max($this->data[$valueKey]);
foreach ($this->data[$valueKey] as &$value) {
$value = $value / $maxValue * 10;
}
}
/**
* graph area for the radar chart does not include grid lines
*/
protected function drawGraphArea()
{
$this->chart->drawGraphArea(
$this->getGraphAreaColor(RED),
$this->getGraphAreaColor(GREEN),
$this->getGraphAreaColor(BLUE),
FALSE
);
$this->chart->drawGraphAreaGradient(
$this->getGraphAreaGradientColor(RED),
$this->getGraphAreaGradientColor(GREEN),
$this->getGraphAreaGradientColor(BLUE),
50
);
}
/**
* draws the radar chart
*/
protected function drawChart()
{
// when drawing radar graph we can specify the border from the top of
// graph area. We want border to be dynamic, so that either the top
// or the side of the radar is some distance away from the top or the
// side of the graph area.
$areaWidth = $this->chart->GArea_X2 - $this->chart->GArea_X1;
$areaHeight = $this->chart->GArea_Y2 - $this->chart->GArea_Y1;
if ($areaHeight > $areaWidth) {
$borderOffset = ($areaHeight - $areaWidth) / 2;
}
else {
$borderOffset = 0;
}
// the least ammount that radar is away from the graph area side.
$borderOffset += 40;
$this->chart->drawRadarAxis($this->dataSet->GetData(),$this->dataSet->GetDataDescription(),TRUE,$borderOffset,120,120,120,230,230,230,-1,2);
$this->chart->drawFilledRadar($this->dataSet->GetData(),$this->dataSet->GetDataDescription(),50,$borderOffset);
}
}
?>

View File

@@ -0,0 +1,35 @@
<?php
/**
* @author Martynas Mickevicius <mmartynas@gmail.com>
* @package phpMyAdmin
*/
/**
*
*/
require_once 'pma_pchart_multi.php';
/**
* implements stacked bar chart
* @package phpMyAdmin
*/
class PMA_pChart_stacked_bar extends PMA_pChart_multi
{
public function __construct($data, $options = null)
{
parent::__construct($data, $options);
}
/**
* draws stacked bar chart
*/
protected function drawChart()
{
parent::drawChart();
// Draw the bar chart
$this->chart->drawStackedBarGraph($this->dataSet->GetData(),$this->dataSet->GetDataDescription(),70);
}
}
?>

View File

@@ -1280,12 +1280,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 '<fieldset><legend>' . __('Profiling') . '</legend>' . "\n";
echo '<div style="float: left;">';
echo '<table>' . "\n";
echo ' <tr>' . "\n";
echo ' <th>' . __('Status') . '</th>' . "\n";
@@ -1297,7 +1299,17 @@ function PMA_profilingResults($profiling_results)
echo '<td>' . $one_result['Status'] . '</td>' . "\n";
echo '<td>' . $one_result['Duration'] . '</td>' . "\n";
}
echo '</table>' . "\n";
echo '</div>';
if ($show_chart) {
require_once './libraries/chart.lib.php';
echo '<div style="float: left;">';
PMA_chart_profiling($profiling_results);
echo '</div>';
}
echo '</fieldset>' . "\n";
}

View File

@@ -2182,6 +2182,12 @@ function PMA_displayResultsOperations($the_disp_mode, $analyzed_sql) {
'tbl_export.php' . PMA_generate_common_url($_url_params),
PMA_getIcon('b_tblexport.png', __('Export'), false, true),
'', true, true, '') . "\n";
// show chart
echo PMA_linkOrButton(
'tbl_chart.php' . PMA_generate_common_url($_url_params),
PMA_getIcon('b_chart.png', __('Display chart'), false, true),
'', true, true, '') . "\n";
}
// CREATE VIEW

View File

@@ -16,6 +16,8 @@ if (! defined('PMA_NO_VARIABLES_IMPORT')) {
}
require_once './libraries/common.inc.php';
$GLOBALS['js_include'][] = 'pMap.js';
/**
* Does the common work
*/
@@ -33,6 +35,11 @@ require './libraries/server_links.inc.php';
require './libraries/replication.inc.php';
require_once './libraries/replication_gui.lib.php';
/**
* Chart generation
*/
require_once './libraries/chart.lib.php';
/**
* Messages are built using the message name
*/
@@ -692,6 +699,13 @@ foreach ($used_queries as $name => $value) {
?>
</tbody>
</table>
<div class="clearfloat"></div>
</div>
<div>
<?php
echo PMA_chart_status($used_queries);
?>
</div>
<div id="serverstatussection">

View File

@@ -14,6 +14,7 @@ require_once './libraries/check_user_privileges.lib.php';
require_once './libraries/bookmark.lib.php';
$GLOBALS['js_include'][] = 'jquery/jquery-ui-1.8.custom.js';
$GLOBALS['js_include'][] = 'pMap.js';
/**
* Defines the url to return to in case of error in a sql statement
@@ -602,7 +603,7 @@ else {
}
if (isset($profiling_results)) {
PMA_profilingResults($profiling_results);
PMA_profilingResults($profiling_results, true);
}
// Displays the results in a table

192
tbl_chart.php Normal file
View File

@@ -0,0 +1,192 @@
<?php
/* vim: set expandtab sw=4 ts=4 sts=4: */
/**
* handles creation of the chart
*
* @version $Id$
* @package phpMyAdmin
*/
/**
* do not import request variable into global scope
* @ignore
*/
if (! defined('PMA_NO_VARIABLES_IMPORT')) {
define('PMA_NO_VARIABLES_IMPORT', true);
}
/**
*
*/
require_once './libraries/common.inc.php';
$GLOBALS['js_include'][] = 'pMap.js';
/**
* Runs common work
*/
require './libraries/db_common.inc.php';
$url_params['goto'] = $cfg['DefaultTabDatabase'];
$url_params['back'] = 'sql.php';
/*
* Import chart functions
*/
require_once './libraries/chart.lib.php';
/*
* Execute the query and return the result
*/
$data = array();
$result = PMA_DBI_try_query($sql_query);
while ($row = PMA_DBI_fetch_assoc($result)) {
$data[] = $row;
}
// get settings if any posted
$chartSettings = array();
if (PMA_isValid($_REQUEST['chartSettings'], 'array')) {
$chartSettings = $_REQUEST['chartSettings'];
}
// get the chart and settings after chart generation
$chart = PMA_chart_results($data, $chartSettings);
if (!empty($chart)) {
$message = PMA_Message::success(__('Chart generated successfully.'));
}
else {
$message = PMA_Message::error(__('The result of this query can\'t be used for a chart. See [a@./Documentation.html#faq6_29@Documentation]FAQ 6.29[/a]'));
}
/**
* Displays top menu links
* We use db links because a chart is not necessarily on a single table
*/
$num_tables = 0;
require_once './libraries/db_links.inc.php';
$url_params['db'] = $GLOBALS['db'];
$url_params['reload'] = 1;
/**
* Displays the page
*/
?>
<!-- Display Chart options -->
<div id="div_view_options">
<form method="post" action="tbl_chart.php">
<?php echo PMA_generate_common_hidden_inputs($url_params); ?>
<fieldset>
<legend><?php echo __('Display chart'); ?></legend>
<div style="float: right">
<?php echo $chart; ?>
</div>
<input type="hidden" name="sql_query" id="sql_query" value="<?php echo $sql_query; ?>" />
<table>
<tr><td><label for="width"><?php echo __("Width"); ?></label></td>
<td><input type="text" name="chartSettings[width]" id="width" value="<?php echo (isset($chartSettings['width']) ? $chartSettings['width'] : ''); ?>" /></td>
</tr>
<tr><td><label for="height"><?php echo __("Height"); ?></label></td>
<td><input type="text" name="chartSettings[height]" id="height" value="<?php echo (isset($chartSettings['height']) ? $chartSettings['height'] : ''); ?>" /></td>
</tr>
<tr><td><label for="titleText"><?php echo __("Title"); ?></label></td>
<td><input type="text" name="chartSettings[titleText]" id="titleText" value="<?php echo (isset($chartSettings['titleText']) ? $chartSettings['titleText'] : ''); ?>" /></td>
</tr>
<?php if ($chartSettings['type'] != 'pie' && $chartSettings['type'] != 'radar') { ?>
<tr><td><label for="xLabel"><?php echo __("X Axis label"); ?></label></td>
<td><input type="text" name="chartSettings[xLabel]" id="xLabel" value="<?php echo (isset($chartSettings['xLabel']) ? $chartSettings['xLabel'] : ''); ?>" /></td>
</tr>
<tr><td><label for="yLabel"><?php echo __("Y Axis label"); ?></label></td>
<td><input type="text" name="chartSettings[yLabel]" id="yLabel" value="<?php echo (isset($chartSettings['yLabel']) ? $chartSettings['yLabel'] : ''); ?>" /></td>
</tr>
<?php } ?>
<tr><td><label for="areaMargins"><?php echo __("Area margins"); ?></label></td>
<td>
<input type="text" name="chartSettings[areaMargins][]" size="2" value="<?php echo (isset($chartSettings['areaMargins'][0]) ? $chartSettings['areaMargins'][0] : ''); ?>" />
<input type="text" name="chartSettings[areaMargins][]" size="2" value="<?php echo (isset($chartSettings['areaMargins'][1]) ? $chartSettings['areaMargins'][1] : ''); ?>" />
<input type="text" name="chartSettings[areaMargins][]" size="2" value="<?php echo (isset($chartSettings['areaMargins'][2]) ? $chartSettings['areaMargins'][2] : ''); ?>" />
<input type="text" name="chartSettings[areaMargins][]" size="2" value="<?php echo (isset($chartSettings['areaMargins'][3]) ? $chartSettings['areaMargins'][3] : ''); ?>" />
</td>
</tr>
<?php if ($chartSettings['legend'] == true) { ?>
<tr><td><label for="legendMargins"><?php echo __("Legend margins"); ?></label></td>
<td>
<input type="text" name="chartSettings[legendMargins][]" size="2" value="<?php echo $chartSettings['legendMargins'][0]; ?>" />
<input type="text" name="chartSettings[legendMargins][]" size="2" value="<?php echo $chartSettings['legendMargins'][1]; ?>" />
<input type="text" name="chartSettings[legendMargins][]" size="2" value="<?php echo $chartSettings['legendMargins'][2]; ?>" />
<input type="text" name="chartSettings[legendMargins][]" size="2" value="<?php echo $chartSettings['legendMargins'][3]; ?>" />
</td>
</tr>
<?php } ?>
<tr><td><label for="type"><?php echo __("Type"); ?></label></td>
<td>
<input type="radio" name="chartSettings[type]" value="bar" <?php echo ($chartSettings['type'] == 'bar' ? 'checked' : ''); ?>><?php echo __('Bar'); ?>
<input type="radio" name="chartSettings[type]" value="line" <?php echo ($chartSettings['type'] == 'line' ? 'checked' : ''); ?>><?php echo __('Line'); ?>
<input type="radio" name="chartSettings[type]" value="radar" <?php echo ($chartSettings['type'] == 'radar' ? 'checked' : ''); ?>><?php echo __('Radar'); ?>
<?php if ($chartSettings['multi'] == false) { ?>
<input type="radio" name="chartSettings[type]" value="pie" <?php echo ($chartSettings['type'] == 'pie' ? 'checked' : ''); ?>><?php echo __('Pie'); ?>
<?php } ?>
</td>
</tr>
<?php if ($chartSettings['type'] == 'bar' && isset($chartSettings['multi']) && $chartSettings['multi'] == true) { ?>
<tr><td><label for="barType"><?php echo __("Bar type"); ?></label></td>
<td>
<input type="radio" name="chartSettings[barType]" value="stacked" <?php echo ($chartSettings['barType'] == 'stacked' ? 'checked' : ''); ?>><?php echo __('Stacked'); ?>
<input type="radio" name="chartSettings[barType]" value="multi" <?php echo ($chartSettings['barType'] == 'multi' ? 'checked' : ''); ?>><?php echo __('Multi'); ?>
</td>
</tr>
<?php } ?>
<tr><td><label for="continuous"><?php echo __("Continuous image"); ?></label></td>
<td>
<input type="checkbox" name="chartSettings[continuous]" id="continuous" <?php echo ($chartSettings['continuous'] == 'on' ? 'checked="checked"' : ''); ?>>
<i><?php echo _('(May not work on IE8)'); ?></i>
</td>
</tr>
<tr><td><label for="fontSize"><?php echo __("Font size"); ?></label></td>
<td><input type="text" name="chartSettings[fontSize]" id="fontSize" value="<?php echo (isset($chartSettings['fontSize']) ? $chartSettings['fontSize'] : ''); ?>" /></td>
</tr>
<?php if ($chartSettings['type'] == 'radar') { ?>
<tr><td colspan="2">
<p>
<?php echo __('When drawing a radar chart all values are normalized to a range [0..10].'); ?>
</p>
</td></tr>
<?php } ?>
<tr><td colspan="2">
<p>
<?php echo __('Note that not every result table can be put to the chart. See <a href="./Documentation.html#faq6_29" target="Documentation">FAQ 6.29</a>'); ?>
</p>
</td></tr>
</table>
</fieldset>
<fieldset class="tblFooters">
<input type="submit" name="displayChart" value="<?php echo __('Redraw'); ?>" />
</fieldset>
</form>
</div>
<?php
/**
* Displays the footer
*/
require_once './libraries/footer.inc.php';
?>

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.0 KiB