2011-04-07 Miguel de Dios <miguel.dedios@artica.es>
* include/graphs/fgraph.php: changed the img tag to autoclose. * include/graphs/functions_fsgraph.php: changed the border to default 1, and fixed the show legend. * include/functions_graph.php: cleaned source code style. And the function "graphic_combined_module2" added the show timestamp as human, add the min, max, avg values. * include/graphs/functions_pchart.php: changed the show leyend in the top of graph, and added some comments lines for debug. * include/functions_reporting.php, include/functions_custom_graphs.php, godmode/reporting/graph_builder.preview.php: changed the graph to show with new engine. git-svn-id: https://svn.code.sf.net/p/pandora/code/trunk@4177 c3f86ba8-e40f-0410-aaad-9ba5e7f4b01f
This commit is contained in:
parent
d0346fc2f5
commit
0daa808bb8
|
@ -1,3 +1,22 @@
|
|||
2011-04-07 Miguel de Dios <miguel.dedios@artica.es>
|
||||
|
||||
* include/graphs/fgraph.php: changed the img tag to autoclose.
|
||||
|
||||
* include/graphs/functions_fsgraph.php: changed the border to default 1, and
|
||||
fixed the show legend.
|
||||
|
||||
* include/functions_graph.php: cleaned source code style. And the function
|
||||
"graphic_combined_module2" added the show timestamp as human, add the
|
||||
min, max, avg values.
|
||||
|
||||
* include/graphs/functions_pchart.php: changed the show leyend in the top
|
||||
of graph, and added some comments lines for debug.
|
||||
|
||||
|
||||
* include/functions_reporting.php, include/functions_custom_graphs.php,
|
||||
godmode/reporting/graph_builder.preview.php: changed the graph to show with
|
||||
new engine.
|
||||
|
||||
2011-04-06 Javier Lanz <javier.lanz@artica.es>
|
||||
|
||||
* pandoradb.sql: Added 'id_group' & 'id_module_group' fields to
|
||||
|
|
|
@ -141,12 +141,21 @@ echo "<table class='databox_frame' cellpadding='0' cellspacing='0'>";
|
|||
echo "<tr><td>";
|
||||
|
||||
if(!empty($modules)) {
|
||||
if ($config['flash_charts']) {
|
||||
echo graphic_combined_module (explode (',', $modules), explode (',', $weights), $period, $width, $height,
|
||||
require_once ($config["homedir"] . '/include/functions_graph.php');
|
||||
|
||||
//if ($config['flash_charts']) {
|
||||
//echo graphic_combined_module (explode (',', $modules), explode (',', $weights), $period, $width, $height,
|
||||
// 'Combined%20Sample%20Graph', '', $events, 0, 0, $stacked, $unixdate);
|
||||
//}
|
||||
//else {
|
||||
//echo "<img src='include/fgraph.php?tipo=combined&id=$modules&weight_l=$weights&label=" . base64_encode ("Combined%20Sample%20Graph") . "&height=$height&width=$width&stacked=$stacked&period=$period&date=$unixdate' border=1 alt=''>";
|
||||
//}
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////////
|
||||
echo graphic_combined_module2(explode (',', $modules), explode (',', $weights), $period, $width, $height,
|
||||
'Combined%20Sample%20Graph', '', $events, 0, 0, $stacked, $unixdate);
|
||||
} else {
|
||||
echo "<img src='include/fgraph.php?tipo=combined&id=$modules&weight_l=$weights&label=" . base64_encode ("Combined%20Sample%20Graph") . "&height=$height&width=$width&stacked=$stacked&period=$period&date=$unixdate' border=1 alt=''>";
|
||||
}
|
||||
|
||||
///////////////////////////////////////////////////////
|
||||
}
|
||||
else {
|
||||
echo "<div class='nf'>".__('Empty graph')."</div>";
|
||||
|
|
|
@ -92,6 +92,8 @@ function get_user_custom_graphs ($id_user = 0, $only_names = false, $returnAllGr
|
|||
function print_custom_graph ($id_graph, $height, $width, $period, $stacked, $return = false, $date = 0) {
|
||||
global $config;
|
||||
|
||||
require_once ($config["homedir"] . '/include/functions_graph.php');
|
||||
|
||||
$sources = get_db_all_rows_field_filter ('tgraph_source', 'id_graph', $id_graph);
|
||||
$modules = array ();
|
||||
$weights = array ();
|
||||
|
@ -106,6 +108,10 @@ function print_custom_graph ($id_graph, $height, $width, $period, $stacked, $ret
|
|||
array_push ($weights, $source['weight']);
|
||||
}
|
||||
|
||||
$output = graphic_combined_module2($modules, $weights, $period, $width, $height,
|
||||
'', '', 0, 0, 0, $stacked, $date);
|
||||
|
||||
/*
|
||||
if ($config['flash_charts']) {
|
||||
$output = graphic_combined_module ($modules, $weights, $period, $width, $height,
|
||||
'', '', 0, 0, 0, $stacked, $date);
|
||||
|
@ -114,6 +120,7 @@ function print_custom_graph ($id_graph, $height, $width, $period, $stacked, $ret
|
|||
$weights = implode (',', $weights);
|
||||
$output = '<img src="include/fgraph.php?tipo=combined&height='.$height.'&width='.$width.'&id='.$modules.'&period='.$period.'&weight_l='.$weights.'&stacked='.$stacked.'&date='.$date.'">';
|
||||
}
|
||||
*/
|
||||
|
||||
if ($return)
|
||||
return $output;
|
||||
|
|
|
@ -310,6 +310,29 @@ function graphic_combined_module2 ($module_list, $weight_list, $period, $width,
|
|||
global $config;
|
||||
global $graphic_type;
|
||||
|
||||
// Set the title and time format
|
||||
|
||||
if ($period <= 3600) {
|
||||
$title_period = __('Last hour');
|
||||
$time_format = 'G:i:s';
|
||||
}
|
||||
elseif ($period <= 86400) {
|
||||
$title_period = __('Last day');
|
||||
$time_format = 'G:i';
|
||||
}
|
||||
elseif ($period <= 604800) {
|
||||
$title_period = __('Last week');
|
||||
$time_format = 'M j';
|
||||
}
|
||||
elseif ($period <= 2419200) {
|
||||
$title_period = __('Last month');
|
||||
$time_format = 'M j';
|
||||
}
|
||||
else {
|
||||
$title_period = __('Last %s days', format_numeric (($period / (3600 * 24)), 2));
|
||||
$time_format = 'M j';
|
||||
}
|
||||
|
||||
// Set variables
|
||||
if ($date == 0) $date = get_system_time();
|
||||
$datelimit = $date - $period;
|
||||
|
@ -332,7 +355,11 @@ function graphic_combined_module2 ($module_list, $weight_list, $period, $width,
|
|||
|
||||
// Set data containers
|
||||
for ($i = 0; $i < $resolution; $i++) {
|
||||
$timestamp = $datelimit + ($interval * $i);
|
||||
$timestamp = $datelimit + ($interval * $i);/*
|
||||
$timestamp_short = date($time_format, $timestamp);
|
||||
$long_index[$timestamp_short] = date(
|
||||
html_entity_decode($config['date_format'], ENT_QUOTES, "UTF-8"), $timestamp);
|
||||
$timestamp = $timestamp_short;*/
|
||||
|
||||
$graph[$timestamp]['count'] = 0;
|
||||
$graph[$timestamp]['timestamp_bottom'] = $timestamp;
|
||||
|
@ -343,6 +370,8 @@ function graphic_combined_module2 ($module_list, $weight_list, $period, $width,
|
|||
$graph[$timestamp]['alert'] = 0;
|
||||
}
|
||||
|
||||
$long_index = array();
|
||||
|
||||
// Calculate data for each module
|
||||
for ($i = 0; $i < $module_number; $i++) {
|
||||
|
||||
|
@ -432,13 +461,25 @@ function graphic_combined_module2 ($module_list, $weight_list, $period, $width,
|
|||
if ($data[0]['utimestamp'] == $datelimit) {
|
||||
$previous_data = $data[0]['datos'];
|
||||
$j++;
|
||||
} else {
|
||||
}
|
||||
else {
|
||||
$previous_data = 0;
|
||||
}
|
||||
|
||||
$max = 0;
|
||||
$min = null;
|
||||
$avg = 0;
|
||||
$countAvg = 0;
|
||||
|
||||
// Calculate chart data
|
||||
for ($l = 0; $l < $resolution; $l++) {
|
||||
$countAvg ++;
|
||||
|
||||
$timestamp = $datelimit + ($interval * $l);
|
||||
$timestamp_short = date($time_format, $timestamp);
|
||||
$long_index[$timestamp_short] = date(
|
||||
html_entity_decode($config['date_format'], ENT_QUOTES, "UTF-8"), $timestamp);
|
||||
//$timestamp = $timestamp_short;
|
||||
|
||||
$total = 0;
|
||||
$count = 0;
|
||||
|
@ -478,33 +519,56 @@ function graphic_combined_module2 ($module_list, $weight_list, $period, $width,
|
|||
// Data
|
||||
if ($count > 0) {
|
||||
//$graph_values[$i][$timestamp] = $total * $weight_list[$i];
|
||||
$temp_graph_values[$timestamp] = $total * $weight_list[$i];
|
||||
$temp_graph_values[$timestamp_short] = $total * $weight_list[$i];
|
||||
|
||||
$previous_data = $total;
|
||||
// Compressed data
|
||||
} else {
|
||||
if ($uncompressed_module || ($timestamp > time ())) {
|
||||
//$graph_values[$i][$timestamp] = 0;
|
||||
$temp_graph_values[$timestamp] = 0;
|
||||
$temp_graph_values[$timestamp_short] = 0;
|
||||
}
|
||||
else {
|
||||
//$graph_values[$i][$timestamp] = $previous_data * $weight_list[$i];
|
||||
$temp_graph_values[$timestamp] = $previous_data * $weight_list[$i];
|
||||
$temp_graph_values[$timestamp_short] = $previous_data * $weight_list[$i];
|
||||
}
|
||||
}
|
||||
|
||||
//Extract max, min, avg
|
||||
if ($max < $temp_graph_values[$timestamp_short]) {
|
||||
$max = $temp_graph_values[$timestamp_short];
|
||||
}
|
||||
|
||||
if (isset($min)) {
|
||||
if ($min > $temp_graph_values[$timestamp_short]) {
|
||||
$min = $temp_graph_values[$timestamp_short];
|
||||
}
|
||||
}
|
||||
else {
|
||||
$min = $temp_graph_values[$timestamp_short];
|
||||
}
|
||||
$avg += $temp_graph_values[$timestamp_short];
|
||||
|
||||
$graph_values[$i] = $temp_graph_values;
|
||||
}
|
||||
|
||||
//Add the max, min and avg in the legend
|
||||
$avg = round($avg / $countAvg, 1);
|
||||
$module_name_list[$i] .= " (".__("Max"). ":$max, ".__("Min"). ":$min, ". __("Avg"). ": $avg)";
|
||||
|
||||
if ($weight_list[$i] != 1) {
|
||||
//$module_name_list[$i] .= " (x". format_numeric ($weight_list[$i], 1).")";
|
||||
$module_name_list[$i] .= " (x". format_numeric ($weight_list[$i], 1).")";
|
||||
}
|
||||
|
||||
$graph_values[$module_name_list[$i]] = $graph_values[$i];
|
||||
unset($graph_values[$i]);
|
||||
//$graph_values[$module_name_list[$i]] = $graph_values[$i];
|
||||
//unset($graph_values[$i]);
|
||||
|
||||
//$graph_values[$i] = $graph_values[$i];
|
||||
|
||||
}
|
||||
|
||||
$temp = array(); //debugPrint($graph_values);
|
||||
$temp = array();
|
||||
foreach ($graph_values as $graph_group => $point) {
|
||||
foreach ($point as $timestamp_point => $point_value) {
|
||||
$temp[$timestamp_point][$graph_group] = $point_value;
|
||||
|
@ -539,8 +603,14 @@ function graphic_combined_module2 ($module_list, $weight_list, $period, $width,
|
|||
////////////////////////////////////////////////////////////////////////////
|
||||
switch ($stacked) {
|
||||
case 0:
|
||||
/*$color = array(
|
||||
0 => array('alpha' => 50),
|
||||
1 => array('alpha' => 50),
|
||||
2 => array('alpha' => 50)
|
||||
);*/
|
||||
$color = null;
|
||||
return area_graph($config['flash_charts'], $graph_values, $width, $height,
|
||||
array(), $module_name_list, array());
|
||||
$color, $module_name_list, $long_index);
|
||||
return;
|
||||
break;
|
||||
default:
|
||||
|
|
|
@ -1898,7 +1898,20 @@ function render_report_html_item ($content, $table, $report, $mini = false) {
|
|||
|
||||
$table->colspan[1][0] = 3;
|
||||
$data = array ();
|
||||
$data[0] = '<img src="include/fgraph.php?tipo=combined&id='.implode (',', $modules).'&weight_l='.implode (',', $weights).'&height='.$sizgraph_h.'&width='.$sizgraph_w.'&period='.$content['period'].'&date='.$report["datetime"].'&stacked='.$graph["stacked"].'&pure=1" border="1" alt="">';
|
||||
//$data[0] = '<img src="include/fgraph.php?tipo=combined&id='.implode (',', $modules).'&weight_l='.implode (',', $weights).'&height='.$sizgraph_h.'&width='.$sizgraph_w.'&period='.$content['period'].'&date='.$report["datetime"].'&stacked='.$graph["stacked"].'&pure=1" border="1" alt="">';
|
||||
require_once ($config["homedir"] . '/include/functions_graph.php');
|
||||
$data[0] = graphic_combined_module2(
|
||||
$modules,
|
||||
$weights,
|
||||
$content['period'],
|
||||
$sizgraph_w, $sizgraph_h,
|
||||
'Combined%20Sample%20Graph',
|
||||
'',
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
$graph["stacked"],
|
||||
$report["datetime"]);
|
||||
array_push ($table->data, $data);
|
||||
|
||||
break;
|
||||
|
|
|
@ -59,7 +59,7 @@ function area_graph($flash_chart, $chart_data, $width, $height, $color,$legend,
|
|||
|
||||
serialize_in_temp($graph, $id_graph);
|
||||
|
||||
return "<img src='http://127.0.0.1/pandora_console/include/graphs/functions_pchart.php?graph_type=area&id_graph=" . $id_graph . "'>";
|
||||
return "<img src='http://127.0.0.1/pandora_console/include/graphs/functions_pchart.php?graph_type=area&id_graph=" . $id_graph . "' />";
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -93,15 +93,15 @@ function fs_area_graph($chart_data, $width, $height, $color, $legend, $long_inde
|
|||
$empty = 1;
|
||||
foreach ($data as $i => $value) {
|
||||
|
||||
$legend = '';
|
||||
$legend_text = '';
|
||||
if (isset($legend[$i])) {
|
||||
$legend = $legend[$i];
|
||||
$legend_text = $legend[$i];
|
||||
}
|
||||
|
||||
$alpha = '';
|
||||
$areaBorderColor = '';
|
||||
$color = '';
|
||||
$showAreaBorder = 0;
|
||||
$showAreaBorder = 1; //0 old default
|
||||
if (isset($color[$i])) {
|
||||
if (!isset($color[$i]['border'])) {
|
||||
$showAreaBorder = 1;
|
||||
|
@ -120,7 +120,7 @@ function fs_area_graph($chart_data, $width, $height, $color, $legend, $long_inde
|
|||
}
|
||||
}
|
||||
|
||||
$chart->addDataSet($legend, $alpha .
|
||||
$chart->addDataSet($legend_text, $alpha .
|
||||
'showAreaBorder=' . $showAreaBorder . ';' .
|
||||
$areaBorderColor .
|
||||
$color);
|
||||
|
|
|
@ -45,6 +45,8 @@ if ($id_graph) {
|
|||
$height = $graph['height'];
|
||||
$colors = $graph['color'];
|
||||
$legend = $graph['legend'];
|
||||
|
||||
//debugPrint($graph, true);
|
||||
/*
|
||||
$colors = array();
|
||||
$colors['pep1'] = array('border' => '#000000', 'color' => '#000000', 'alpha' => 50);
|
||||
|
@ -53,6 +55,10 @@ if ($id_graph) {
|
|||
$colors['pep4'] = array('border' => '#000000', 'color' => '#0000ff', 'alpha' => 50);
|
||||
*/
|
||||
$rgb_color = array();
|
||||
|
||||
if (!isset($colors))
|
||||
$colors = array();
|
||||
|
||||
foreach($colors as $i => $color) {
|
||||
$rgb['border'] = html2rgb($color['border']);
|
||||
$rgb_color[$i]['border']['R'] = $rgb['border'][0];
|
||||
|
@ -66,6 +72,26 @@ if ($id_graph) {
|
|||
|
||||
$rgb_color[$i]['alpha'] = $color['alpha'];
|
||||
}
|
||||
|
||||
/*foreach($colors as $i => $color) {
|
||||
if (isset($color['border'])) {
|
||||
$rgb['border'] = html2rgb($color['border']);
|
||||
$rgb_color[$i]['border']['R'] = $rgb['border'][0];
|
||||
$rgb_color[$i]['border']['G'] = $rgb['border'][1];
|
||||
$rgb_color[$i]['border']['B'] = $rgb['border'][2];
|
||||
}
|
||||
|
||||
if (isset($color['color'])) {
|
||||
$rgb['color'] = html2rgb($color['color']);
|
||||
$rgb_color[$i]['color']['R'] = $rgb['color'][0];
|
||||
$rgb_color[$i]['color']['G'] = $rgb['color'][1];
|
||||
$rgb_color[$i]['color']['B'] = $rgb['color'][2];
|
||||
}
|
||||
|
||||
if (isset($color['color'])) {
|
||||
$rgb_color[$i]['alpha'] = $color['alpha'];
|
||||
}
|
||||
}*/
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -338,6 +364,23 @@ function pch_vertical_graph ($graph_type, $index, $data, $width, $height, $rgb_c
|
|||
"BorderG" => $rgb_color[$i]['border']["G"],
|
||||
"BorderB" => $rgb_color[$i]['border']["B"],
|
||||
"Alpha" => $rgb_color[$i]['alpha']));
|
||||
|
||||
/*$palette_color = array();
|
||||
if (isset($rgb_color[$i]['color'])) {
|
||||
$palette_color["R"] = $rgb_color[$i]['color']["R"];
|
||||
$palette_color["G"] = $rgb_color[$i]['color']["G"];
|
||||
$palette_color["B"] = $rgb_color[$i]['color']["B"];
|
||||
}
|
||||
if (isset($rgb_color[$i]['color'])) {
|
||||
$palette_color["BorderR"] = $rgb_color[$i]['border']["R"];
|
||||
$palette_color["BorderG"] = $rgb_color[$i]['border']["G"];
|
||||
$palette_color["BorderB"] = $rgb_color[$i]['border']["B"];
|
||||
}
|
||||
if (isset($rgb_color[$i]['color'])) {
|
||||
$palette_color["Alpha"] = $rgb_color[$i]['Alpha'];
|
||||
}
|
||||
|
||||
$MyData->setPalette($point_id, $palette_color);*/
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -347,6 +390,8 @@ function pch_vertical_graph ($graph_type, $index, $data, $width, $height, $rgb_c
|
|||
$MyData->setSerieDescription("Xaxis", $xaxisname);
|
||||
$MyData->setAbscissa("Xaxis");
|
||||
|
||||
|
||||
|
||||
/* Create the pChart object */
|
||||
$myPicture = new pImage($width,$height,$MyData);
|
||||
|
||||
|
@ -357,25 +402,38 @@ function pch_vertical_graph ($graph_type, $index, $data, $width, $height, $rgb_c
|
|||
//$myPicture->drawRectangle(0,0,$width,$height,array("R"=>0,"G"=>0,"B"=>0));
|
||||
|
||||
/* Set the default font */
|
||||
$myPicture->setFontProperties(array("FontName"=>"../fonts/code.ttf","FontSize"=>7));
|
||||
|
||||
/* Define the chart area */
|
||||
$myPicture->setGraphArea(30,20,$width,$height-100);
|
||||
|
||||
/* Draw the scale */
|
||||
$scaleSettings = array("GridR"=>200,"GridG"=>200,"GridB"=>200,"DrawSubTicks"=>TRUE,"CycleBackground"=>TRUE, "Mode"=>SCALE_MODE_START0, "XMargin" => 40, "LabelRotation" => 90);
|
||||
$myPicture->drawScale($scaleSettings);
|
||||
$myPicture->setFontProperties(array("FontName"=>"../fonts/code.ttf","FontSize"=>10));
|
||||
|
||||
if(isset($legend)) {
|
||||
/* Write the chart legend */
|
||||
$myPicture->drawLegend($height/2,$height-20,array("Style"=>LEGEND_NOBORDER,"Mode"=>LEGEND_HORIZONTAL));
|
||||
$size = $myPicture->getLegendSize(array("Style"=>LEGEND_NOBORDER,"Mode"=>LEGEND_VERTICAL));
|
||||
$myPicture->drawLegend($width-$size['Width'], 8,array("Style"=>LEGEND_NOBORDER,"Mode"=>LEGEND_VERTICAL));
|
||||
}
|
||||
|
||||
if (isset($size['Height'])) {
|
||||
/* Define the chart area */
|
||||
$myPicture->setGraphArea(30,$size['Height'],$width,$height - 60);
|
||||
}
|
||||
else {
|
||||
/* Define the chart area */
|
||||
$myPicture->setGraphArea(30, 5,$width,$height - 60);
|
||||
}
|
||||
|
||||
/* Draw the scale */
|
||||
$scaleSettings = array("GridR"=>200,
|
||||
"GridG"=>200,
|
||||
"GridB"=>200,
|
||||
"DrawSubTicks"=>TRUE,
|
||||
"CycleBackground"=>TRUE, "Mode"=>SCALE_MODE_START0, "LabelRotation" => 60);
|
||||
$myPicture->drawScale($scaleSettings);
|
||||
|
||||
|
||||
|
||||
/* Turn on shadow computing */
|
||||
//$myPicture->setShadow(TRUE,array("X"=>0,"Y"=>1,"R"=>0,"G"=>0,"B"=>0,"Alpha"=>10));
|
||||
|
||||
/* Draw the chart */
|
||||
$settings = array("ForceTransparency"=>"-1",
|
||||
$settings = array("ForceTransparency"=>"50", //
|
||||
"Gradient"=>TRUE,
|
||||
"GradientMode"=>GRADIENT_EFFECT_CAN,
|
||||
"DisplayValues"=>$show_values,
|
||||
|
|
Loading…
Reference in New Issue