2011-04-11 Miguel de Dios <miguel.dedios@artica.es>

* 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
This commit is contained in:
mdtrooper 2011-04-11 16:45:03 +00:00
parent 827898cc21
commit 7e770bba09
5 changed files with 96 additions and 42 deletions

View File

@ -1,3 +1,15 @@
2011-04-11 Miguel de Dios <miguel.dedios@artica.es>
* 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 <javier.lanz@artica.es> 2011-04-11 Javier Lanz <javier.lanz@artica.es>
* godmode/reporting/reporting_builder.item_editor.php: The SLA elements * godmode/reporting/reporting_builder.item_editor.php: The SLA elements

View File

@ -145,7 +145,14 @@ print_select ($periods, 'period', $period);
echo "</td><td class='datos2'>"; echo "</td><td class='datos2'>";
echo "<b>".__('Stacked')."</b></td>"; echo "<b>".__('Stacked')."</b></td>";
echo "<td class='datos2'>"; echo "<td class='datos2'>";
$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); print_select ($stackeds, 'stacked', $stacked);
echo "</td>"; echo "</td>";

View File

@ -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 '<img src="' . $no_data_image . '" />';
}
if($flash_chart) { if($flash_chart) {
return fs_area_graph($chart_data, $width, $height, $color, $legend, $long_index); 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 '<img src="' . $no_data_image . '" />';
}
if($flash_chart) { if($flash_chart) {
return fs_stacked_graph($chart_data, $width, $height, $color, $legend, $long_index); 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 { else {
$id_graph = uniqid(); $id_graph = uniqid();
$temp_data = array();
if (isset($legend)) {
$temp_legend = array();
}
if (isset($color)) {
$temp_color = array();
}
//Stack the data //Stack the data
foreach ($chart_data as $val_x => $graphs) { stack_data($chart_data, $legend, $color);
$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);
}
$graph = array(); $graph = array();
$graph['data'] = $chart_data; $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); serialize_in_temp($graph, $id_graph);
return "<img src='http://127.0.0.1/pandora_console/include/graphs/functions_pchart.php?graph_type=stacked_area&id_graph=" . $id_graph . "' />"; return "<img src='http://127.0.0.1/pandora_console/include/graphs/functions_pchart.php?graph_type=stacked_area&id_graph=" . $id_graph . "' />";
} }
} }
function stacked_line_graph($flash_chart, $chart_data, $width, $height, $color, $legend, $long_index, $no_data_image) {
if (empty($chart_data)) {
return '<img src="' . $no_data_image . '" />';
}
//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 "<img src='http://127.0.0.1/pandora_console/include/graphs/functions_pchart.php?graph_type=line&id_graph=" . $id_graph . "' />";
}
}
function line_graph($flash_chart, $chart_data, $width, $height, $color, $legend, $long_index) { function line_graph($flash_chart, $chart_data, $width, $height, $color, $legend, $long_index, $no_data_image) {
$flash_chart = 1; if (empty($chart_data)) {
return '<img src="' . $no_data_image . '" />';
}
if($flash_chart) { if($flash_chart) {
return fs_line_graph($chart_data, $width, $height, $color, $legend, $long_index); return fs_line_graph($chart_data, $width, $height, $color, $legend, $long_index);

View File

@ -54,9 +54,11 @@ $width = $graph['width'];
$height = $graph['height']; $height = $graph['height'];
$colors = $graph['color']; $colors = $graph['color'];
$legend = $graph['legend']; $legend = $graph['legend'];
$xaxisname = '';
if(isset($graph['xaxisname'])) { if(isset($graph['xaxisname'])) {
$xaxisname = $graph['xaxisname']; $xaxisname = $graph['xaxisname'];
} }
$yaxisname = '';
if(isset($graph['yaxisname'])) { if(isset($graph['yaxisname'])) {
$yaxisname = $graph['yaxisname']; $yaxisname = $graph['yaxisname'];
} }
@ -122,7 +124,7 @@ switch($graph_type) {
case 'radar': case 'radar':
case 'progress': case 'progress':
case 'area': case 'area':
case 'spline': case 'line':
case 'threshold': case 'threshold':
case 'scatter': case 'scatter':
foreach($data as $i => $d) { foreach($data as $i => $d) {

View File

@ -68,4 +68,35 @@ function reverse_data($array) {
return $array2; 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);
}
}
?> ?>