From fbe9ae0090bec0f5aa21e92845592da873d9be64 Mon Sep 17 00:00:00 2001 From: mdtrooper Date: Mon, 11 Apr 2011 16:45:03 +0000 Subject: [PATCH] 2011-04-11 Miguel de Dios * godmode/reporting/graph_builder.main.php: changed to use constants. * include/graphs/fgraph.php: dded the show image when none data and added the function "stacked_line_graph". * include/graphs/functions_pchart.php: fixed when haven't the $xaxisname and $yaxisname. Fixed typo mistake. * include/graphs/functions_utils.php: added function "stack_data". git-svn-id: https://svn.code.sf.net/p/pandora/code/trunk@4186 c3f86ba8-e40f-0410-aaad-9ba5e7f4b01f --- pandora_console/ChangeLog | 12 +++ .../godmode/reporting/graph_builder.main.php | 9 +- pandora_console/include/graphs/fgraph.php | 82 ++++++++++--------- .../include/graphs/functions_pchart.php | 4 +- .../include/graphs/functions_utils.php | 31 +++++++ 5 files changed, 96 insertions(+), 42 deletions(-) diff --git a/pandora_console/ChangeLog b/pandora_console/ChangeLog index a432951d5b..163fabb8a5 100644 --- a/pandora_console/ChangeLog +++ b/pandora_console/ChangeLog @@ -1,3 +1,15 @@ +2011-04-11 Miguel de Dios + + * godmode/reporting/graph_builder.main.php: changed to use constants. + + * include/graphs/fgraph.php: dded the show image when none data + and added the function "stacked_line_graph". + + * include/graphs/functions_pchart.php: fixed when haven't the $xaxisname and + $yaxisname. Fixed typo mistake. + + * include/graphs/functions_utils.php: added function "stack_data". + 2011-04-11 Javier Lanz * godmode/reporting/reporting_builder.item_editor.php: The SLA elements diff --git a/pandora_console/godmode/reporting/graph_builder.main.php b/pandora_console/godmode/reporting/graph_builder.main.php index 89baccff87..31305a44ca 100644 --- a/pandora_console/godmode/reporting/graph_builder.main.php +++ b/pandora_console/godmode/reporting/graph_builder.main.php @@ -145,7 +145,14 @@ print_select ($periods, 'period', $period); echo ""; echo "".__('Stacked').""; echo ""; -$stackeds = array(__('Area'), __('Stacked area'), __('Line'), __('Stacked line')); + +include_once($config["homedir"] . "/include/functions_graph.php"); + +$stackeds = array( + GRAPH_AREA => __('Area'), + GRAPH_STACKED_AREA => __('Stacked area'), + GRAPH_LINE => __('Line'), + GRAPH_STACKED_LINE => __('Stacked line')); print_select ($stackeds, 'stacked', $stacked); echo ""; diff --git a/pandora_console/include/graphs/fgraph.php b/pandora_console/include/graphs/fgraph.php index b02891f809..bf340f568e 100755 --- a/pandora_console/include/graphs/fgraph.php +++ b/pandora_console/include/graphs/fgraph.php @@ -42,7 +42,11 @@ function threshold_graph($flash_chart, $chart_data, $width, $height) { } } -function area_graph($flash_chart, $chart_data, $width, $height, $color, $legend, $long_index) { +function area_graph($flash_chart, $chart_data, $width, $height, $color, $legend, $long_index, $no_data_image) { + if (empty($chart_data)) { + return ''; + } + if($flash_chart) { return fs_area_graph($chart_data, $width, $height, $color, $legend, $long_index); } @@ -62,7 +66,11 @@ 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) { +function stacked_area_graph($flash_chart, $chart_data, $width, $height, $color, $legend, $long_index, $no_data_image) { + + if (empty($chart_data)) { + return ''; + } if($flash_chart) { return fs_stacked_graph($chart_data, $width, $height, $color, $legend, $long_index); @@ -70,42 +78,8 @@ function stacked_area_graph($flash_chart, $chart_data, $width, $height, $color, else { $id_graph = uniqid(); - $temp_data = array(); - if (isset($legend)) { - $temp_legend = array(); - } - if (isset($color)) { - $temp_color = array(); - } //Stack the data - foreach ($chart_data as $val_x => $graphs) { - $prev_val = 0; - $key = 1000; - foreach ($graphs as $graph => $val_y) { - $chart_data[$val_x][$graph] += $prev_val; - $prev_val = $chart_data[$val_x][$graph]; - $temp_data[$val_x][$key] = $chart_data[$val_x][$graph]; - if (isset($color)) { - $temp_color[$key] = $color[$graph]; - } - if (isset($legend)) { - $temp_legend[$key] = $legend[$graph]; - } - $key--; - } - ksort($temp_data[$val_x]); - } - - $chart_data = $temp_data; - if (isset($legend)) { - $legend = $temp_legend; - ksort($legend); - } - if (isset($color)) { - $color = $temp_color; - ksort($color); - } - + stack_data($chart_data, $legend, $color); $graph = array(); $graph['data'] = $chart_data; @@ -117,12 +91,40 @@ function stacked_area_graph($flash_chart, $chart_data, $width, $height, $color, serialize_in_temp($graph, $id_graph); return ""; - } + } } +function stacked_line_graph($flash_chart, $chart_data, $width, $height, $color, $legend, $long_index, $no_data_image) { + if (empty($chart_data)) { + return ''; + } + + //Stack the data + stack_data($chart_data, $legend, $color); + + if($flash_chart) { + return fs_line_graph($chart_data, $width, $height, $color, $legend, $long_index); + } + else { + $id_graph = uniqid(); + + $graph = array(); + $graph['data'] = $chart_data; + $graph['width'] = $width; + $graph['height'] = $height; + $graph['color'] = $color; + $graph['legend'] = $legend; + + serialize_in_temp($graph, $id_graph); + + return ""; + } +} -function line_graph($flash_chart, $chart_data, $width, $height, $color, $legend, $long_index) { - $flash_chart = 1; +function line_graph($flash_chart, $chart_data, $width, $height, $color, $legend, $long_index, $no_data_image) { + if (empty($chart_data)) { + return ''; + } if($flash_chart) { return fs_line_graph($chart_data, $width, $height, $color, $legend, $long_index); diff --git a/pandora_console/include/graphs/functions_pchart.php b/pandora_console/include/graphs/functions_pchart.php index 5ddeefb85f..c8063d520c 100755 --- a/pandora_console/include/graphs/functions_pchart.php +++ b/pandora_console/include/graphs/functions_pchart.php @@ -54,9 +54,11 @@ $width = $graph['width']; $height = $graph['height']; $colors = $graph['color']; $legend = $graph['legend']; +$xaxisname = ''; if(isset($graph['xaxisname'])) { $xaxisname = $graph['xaxisname']; } +$yaxisname = ''; if(isset($graph['yaxisname'])) { $yaxisname = $graph['yaxisname']; } @@ -122,7 +124,7 @@ switch($graph_type) { case 'radar': case 'progress': case 'area': - case 'spline': + case 'line': case 'threshold': case 'scatter': foreach($data as $i => $d) { diff --git a/pandora_console/include/graphs/functions_utils.php b/pandora_console/include/graphs/functions_utils.php index 7742025f42..768d284ea9 100644 --- a/pandora_console/include/graphs/functions_utils.php +++ b/pandora_console/include/graphs/functions_utils.php @@ -68,4 +68,35 @@ function reverse_data($array) { return $array2; } + + +function stack_data(&$chart_data, &$legend = null, &$color = null) { + foreach ($chart_data as $val_x => $graphs) { + $prev_val = 0; + $key = 1000; + foreach ($graphs as $graph => $val_y) { + $chart_data[$val_x][$graph] += $prev_val; + $prev_val = $chart_data[$val_x][$graph]; + $temp_data[$val_x][$key] = $chart_data[$val_x][$graph]; + if (isset($color)) { + $temp_color[$key] = $color[$graph]; + } + if (isset($legend)) { + $temp_legend[$key] = $legend[$graph]; + } + $key--; + } + ksort($temp_data[$val_x]); + } + + $chart_data = $temp_data; + if (isset($legend)) { + $legend = $temp_legend; + ksort($legend); + } + if (isset($color)) { + $color = $temp_color; + ksort($color); + } +} ?>