implementation of the pie chart using OFC

This commit is contained in:
Martynas Mickevicius
2010-06-14 23:36:52 +03:00
parent 1f378cef7f
commit 9e25d0536d
5 changed files with 214 additions and 5 deletions

View File

@@ -7,9 +7,12 @@
* @package phpMyAdmin * @package phpMyAdmin
*/ */
function PMA_chart_pie($data) function PMA_chart_pie($titleText, $data)
{ {
return "pie chart placeholder"; require_once('./libraries/chart/pma_ofc_pie.php');
$chart = new PMA_OFC_Pie($titleText, $data);
echo $chart->toString();
} }
?> ?>

View File

@@ -0,0 +1,58 @@
<?php
class PMA_Chart
{
/*
* The style of the chart title.
*/
protected $titleStyle = 'font-size: 12px; font-weight: bold;';
/*
* Colors for the different slices in the pie chart.
*/
protected $colors = array(
'#485E70',
'#484A70',
'#594870',
'#6D4870',
'#70485E',
'#70484A',
'#705948',
'#706D48',
'#5E7048',
'#4A7048',
'#487059',
'#48706D',
'#5F7E95',
'#839CAF',
'#95775F',
'#AF9683',
);
/*
* Chart background color.
*/
protected $bgColor = '#f5f5f5';
/*
* The width of the chart.
*/
protected $width = 400;
/*
* The height of the 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);
}
}
?>

View File

@@ -0,0 +1,89 @@
<?php
require_once('pma_chart.php');
/*
* Base class for every chart implemented using OFC.
* Has the code used to embed OFC chart into the page.
*/
class PMA_OFC_Chart extends PMA_Chart
{
protected $flashBaseUrl = 'js/';
protected $chart = null;
function __construct()
{
parent::__construct();
}
function get_embed_code($data)
{
$url = urlencode($url);
// output buffer
$out = array();
// check for http or https:
if (isset($_SERVER['HTTPS']))
{
if (strtoupper ($_SERVER['HTTPS']) == 'ON')
{
$protocol = 'https';
}
else
{
$protocol = 'http';
}
}
else
{
$protocol = 'http';
}
// if there are more than one charts on the
// page, give each a different ID
global $open_flash_chart_seqno;
$chart_id = 'chart';
if (!isset($open_flash_chart_seqno))
{
$open_flash_chart_seqno = 1;
}
else
{
$open_flash_chart_seqno++;
}
$obj_id .= '_'. $open_flash_chart_seqno;
$data_func_name = 'get_data_for_'.$obj_id;
// all parameters for the OFC will be given by the return value
// of the JS function
$out[] = '<script type="text/javascript">';
$out[] = 'function '.$data_func_name.'()';
$out[] = '{';
$out[] = "return '".str_replace("\n", '', $data)."';";
$out[] = '}';
$out[] = '</script>';
$out[] = '<object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" codebase="'.$protocol.'://fpdownload.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=8,0,0,0" ';
$out[] = 'width="'.$this->width.'" height="'.$this->height.'" id="'.$obj_id.'" align="middle">';
$out[] = '<param name="allowScriptAccess" value="sameDomain" />';
$out[] = '<param name="movie" value="'.$this->flashBaseUrl.'open-flash-chart.swf?get-data='.$data_func_name.'" />';
$out[] = '<param name="quality" value="high" />';
$out[] = '<param name="bgcolor" value="#FFFFFF" />';
$out[] = '<embed src="'.$this->flashBaseUrl.'open-flash-chart.swf?get-data='.$data_func_name.'" quality="high" bgcolor="#FFFFFF" width="'.$this->width.'" height="'.$this->height.'" name="'.$obj_id.'" align="middle" allowScriptAccess="sameDomain" ';
$out[] = 'type="application/x-shockwave-flash" pluginspage="'.$protocol.'://www.macromedia.com/go/getflashplayer" id="'.$obj_id.'"/>';
$out[] = '</object>';
return implode("\n", $out);
}
function toString()
{
return $this->get_embed_code($this->chart->toPrettyString());
}
}
?>

View File

@@ -0,0 +1,46 @@
<?php
require_once('pma_ofc_chart.php');
/*
* Implementation of pie chart using OFC.
*/
class PMA_OFC_Pie extends PMA_OFC_Chart
{
function __construct($titleText, $data)
{
parent::__construct();
include './libraries/chart/ofc/open-flash-chart.php';
// create and style chart title
$title = new title($titleText);
$title->set_style($this->titleStyle);
// create the main chart element - pie
$pie = new pie();
$pie->set_alpha(1);
$pie->set_start_angle(35);
$pie->add_animation(new pie_fade());
$pie->add_animation(new pie_bounce(10));
$pie->set_tooltip('#val# '._('of').' #total#<br>#percent# '._('of').' 100%');
$pie->set_colours($this->colors);
$values = array();
foreach($data as $key => $value) {
$values[] = new pie_value($value, $key);
}
$pie->set_values($values);
$pie->gradient_fill();
// create chart
$this->chart = new open_flash_chart();
$this->chart->x_axis = null;
$this->chart->set_bg_colour($this->bgColor);
$this->chart->set_title($title);
$this->chart->add_element($pie);
}
}
?>

View File

@@ -587,9 +587,22 @@ foreach ($used_queries as $name => $value) {
?> ?>
</tbody> </tbody>
</table> </table>
<div> </div>
<?php echo PMA_chart_pie($used_queries); ?>
</div> <div>
<table>
<tr><td>
<?php
// format keys which will be shown in the chart
$chart_data = array();
foreach($used_queries as $key => $value) {
$key = str_replace(array('Com_', '_'), array('', ' '), $key);
$chart_data[ucwords($key)] = (int)$value;
}
echo PMA_chart_pie(__('Query type'), $chart_data);
?>
</td></tr>
</table>
</div> </div>
<div id="serverstatussection"> <div id="serverstatussection">