From d96efd81207857096c32284250d0b1969894fd76 Mon Sep 17 00:00:00 2001 From: zarzuelo Date: Thu, 14 Apr 2011 08:25:41 +0000 Subject: [PATCH] 2011-04-14 Sergio Martin * include/graphs/functions_pchart.php include/graphs/functions_gd.php include/graphs/fgraph.php: Added x and y axis name possibility to line, stacked line and stacked area graphs. Added dual posibility of calling to functions_gd (thorugh url and with function call). Clean code. git-svn-id: https://svn.code.sf.net/p/pandora/code/trunk@4219 c3f86ba8-e40f-0410-aaad-9ba5e7f4b01f --- pandora_console/ChangeLog | 11 ++++ pandora_console/include/graphs/fgraph.php | 48 ++++++++++++++-- .../include/graphs/functions_gd.php | 56 ++++++++++++++++++- .../include/graphs/functions_pchart.php | 2 - 4 files changed, 109 insertions(+), 8 deletions(-) diff --git a/pandora_console/ChangeLog b/pandora_console/ChangeLog index 6e724f1aca..04bc188d52 100644 --- a/pandora_console/ChangeLog +++ b/pandora_console/ChangeLog @@ -1,3 +1,14 @@ +2011-04-14 Sergio Martin + + * include/graphs/functions_pchart.php + include/graphs/functions_gd.php + include/graphs/fgraph.php: Added x and y + axis name possibility to line, stacked line and + stacked area graphs. + Added dual posibility of calling to functions_gd + (thorugh url and with function call). + Clean code. + 2011-04-14 Junichi Satoh * extras/pandoradb_migrate_v3.2_to_v4.0.sql, diff --git a/pandora_console/include/graphs/fgraph.php b/pandora_console/include/graphs/fgraph.php index 5d3c9b6fc5..670c75a683 100755 --- a/pandora_console/include/graphs/fgraph.php +++ b/pandora_console/include/graphs/fgraph.php @@ -10,7 +10,6 @@ // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // GNU General Public License for more details. - // If is called from index if(file_exists('include/functions.php')) { include_once('include/functions.php'); @@ -54,11 +53,44 @@ switch($graph_type) { $title = get_parameter('title'); $mode = get_parameter('mode', 1); - + gd_progress_bar ($width, $height, $progress, $title, $font, $out_of_lim_str, $out_of_lim_image, $mode); break; } +function histogram($chart_data, $width, $height, $font, $max, $title, $mode) { + $graph = array(); + $graph['data'] = $chart_data; + $graph['width'] = $width; + $graph['height'] = $height; + $graph['font'] = $font; + $graph['max'] = $max; + $graph['title'] = $title; + $graph['mode'] = $mode; + + $id_graph = serialize_in_temp($graph); + + return ""; +} + +function progressbar($progress, $width, $height, $title, $font, $mode = 1, $out_of_lim_str = false, $out_of_lim_image = false) { + $graph = array(); + + $graph['progress'] = $progress; + $graph['width'] = $width; + $graph['height'] = $height; + $graph['out_of_lim_str'] = $out_of_lim_str; + $graph['out_of_lim_image'] = $out_of_lim_image; + $graph['title'] = $title; + $graph['font'] = $font; + $graph['mode'] = $mode; + + $id_graph = serialize_in_temp($graph); + + return ""; +} + + function slicesbar_graph($chart_data, $width, $height, $colors, $font, $round_corner) { $graph = array(); $graph['data'] = $chart_data; @@ -126,7 +158,7 @@ function area_graph($flash_chart, $chart_data, $width, $height, $color, $legend, } } -function stacked_area_graph($flash_chart, $chart_data, $width, $height, $color, $legend, $long_index, $no_data_image) { +function stacked_area_graph($flash_chart, $chart_data, $width, $height, $color, $legend, $long_index, $no_data_image, $xaxisname = "", $yaxisname = "") { if (empty($chart_data)) { return ''; @@ -145,6 +177,8 @@ function stacked_area_graph($flash_chart, $chart_data, $width, $height, $color, $graph['height'] = $height; $graph['color'] = $color; $graph['legend'] = $legend; + $graph['xaxisname'] = $xaxisname; + $graph['yaxisname'] = $yaxisname; $id_graph = serialize_in_temp($graph); @@ -152,7 +186,7 @@ function stacked_area_graph($flash_chart, $chart_data, $width, $height, $color, } } -function stacked_line_graph($flash_chart, $chart_data, $width, $height, $color, $legend, $long_index, $no_data_image) { +function stacked_line_graph($flash_chart, $chart_data, $width, $height, $color, $legend, $long_index, $no_data_image, $xaxisname = "", $yaxisname = "") { if (empty($chart_data)) { return ''; } @@ -170,6 +204,8 @@ function stacked_line_graph($flash_chart, $chart_data, $width, $height, $color, $graph['height'] = $height; $graph['color'] = $color; $graph['legend'] = $legend; + $graph['xaxisname'] = $xaxisname; + $graph['yaxisname'] = $yaxisname; $id_graph = serialize_in_temp($graph); @@ -177,7 +213,7 @@ function stacked_line_graph($flash_chart, $chart_data, $width, $height, $color, } } -function line_graph($flash_chart, $chart_data, $width, $height, $color, $legend, $long_index, $no_data_image) { +function line_graph($flash_chart, $chart_data, $width, $height, $color, $legend, $long_index, $no_data_image, $xaxisname = "", $yaxisname = "") { if (empty($chart_data)) { return ''; } @@ -192,6 +228,8 @@ function line_graph($flash_chart, $chart_data, $width, $height, $color, $legend, $graph['height'] = $height; $graph['color'] = $color; $graph['legend'] = $legend; + $graph['xaxisname'] = $xaxisname; + $graph['yaxisname'] = $yaxisname; $id_graph = serialize_in_temp($graph); diff --git a/pandora_console/include/graphs/functions_gd.php b/pandora_console/include/graphs/functions_gd.php index 46ef6125ba..6c1c7f6d63 100755 --- a/pandora_console/include/graphs/functions_gd.php +++ b/pandora_console/include/graphs/functions_gd.php @@ -12,6 +12,60 @@ // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // GNU Lesser General Public License for more details. +// If is called from index +if(file_exists('include/functions.php')) { + include_once('include/functions.php'); + include_once('include/functions_html.php'); + include_once('include/graphs/functions_utils.php'); +} // If is called through url +else if(file_exists('../functions.php')) { + include_once('../functions.php'); + include_once('../functions_html.php'); + include_once('../functions_html.php'); + include_once('functions_utils.php'); +} + +$id_graph = get_parameter('id_graph', false); + +if($id_graph) { + + + if (!$id_graph) { + exit; + } + + $graph = unserialize_in_temp($id_graph); + + if (!isset($graph)) { + exit; + } + + $graph_type = get_parameter('graph_type', ''); + + switch($graph_type) { + case 'histogram': + gd_histogram ($graph['width'], + $graph['height'], + $graph['mode'], + json_decode($graph['data'], true), + $graph['max'], + $graph['font'], + $graph['title']); + break; + case 'progressbar': + gd_progress_bar ($graph['width'], + $graph['height'], + $graph['progress'], + $graph['title'], + $graph['font'], + $graph['out_of_lim_str'], + $graph['out_of_lim_image'], + $graph['mode']); + break; + } +} + + function gd_histogram ($width, $height, $mode, $data, $max_value, $font, $title) { // $title is for future use $nvalues = count($data); @@ -93,7 +147,7 @@ function gd_progress_bar ($width, $height, $progress, $title, $font, $out_of_lim if($out_of_lim_str === false) { $out_of_lim_str = "Out of limits"; } - + if($out_of_lim_image === false) { $out_of_lim_image = "images_graphs/outlimits.png"; } diff --git a/pandora_console/include/graphs/functions_pchart.php b/pandora_console/include/graphs/functions_pchart.php index d77fa4c6a4..bab29afa9b 100755 --- a/pandora_console/include/graphs/functions_pchart.php +++ b/pandora_console/include/graphs/functions_pchart.php @@ -593,12 +593,10 @@ function pch_vertical_graph ($graph_type, $index, $data, $width, $height, $rgb_c if (isset($size['Height'])) { /* Define the chart area */ - //$myPicture->setGraphArea(40,$size['Height'],$width,$height - 90); $myPicture->setGraphArea(40,$size['Height'],$width,$height - $margin_bottom); } else { /* Define the chart area */ - //$myPicture->setGraphArea(40, 5,$width,$height - 90); $myPicture->setGraphArea(40, 5,$width,$height - $margin_bottom); }