2013-01-30 Miguel de Dios <miguel.dedios@artica.es>

* operation/agentes/estado_generalagente.php,
	include/functions_graph.php, include/graphs/functions_flot.php,
	include/graphs/fgraph.php, include/graphs/flot/pandora.flot.js:
	fixed the graph of events, now the pie graphs in "flot mode" has
	a parammeter to force the position of legend.
	
	Fixes: #3602206




git-svn-id: https://svn.code.sf.net/p/pandora/code/trunk@7553 c3f86ba8-e40f-0410-aaad-9ba5e7f4b01f
This commit is contained in:
mdtrooper 2013-01-30 16:29:49 +00:00
parent be7e5dc1f4
commit b06436b3d0
6 changed files with 151 additions and 94 deletions

View File

@ -1,3 +1,13 @@
2013-01-30 Miguel de Dios <miguel.dedios@artica.es>
* operation/agentes/estado_generalagente.php,
include/functions_graph.php, include/graphs/functions_flot.php,
include/graphs/fgraph.php, include/graphs/flot/pandora.flot.js:
fixed the graph of events, now the pie graphs in "flot mode" has
a parammeter to force the position of legend.
Fixes: #3602206
2013-01-30 Juan Manuel Ramon <juanmanuel.ramon@artica.es>
* extras/pandoradb_migrate_4.0.x_to_5.0.mysql.sql

View File

@ -26,66 +26,7 @@ define("GRAPH_LINE", 2);
define("GRAPH_STACKED_LINE", 3);
function get_graph_statistics ($chart_array) {
/// IMPORTANT!
///
/// The calculus for AVG, MIN and MAX values are in this function
/// because it must be done based on graph array data not using reporting
/// function to get coherent data between stats and graph visualization
$stats = array ();
$count = 0;
$size = sizeof($chart_array);
//Initialize stats array
$stats = array ("avg" => 0, "min" => null, "max" => null, "last" => 0);
foreach ($chart_array as $item) {
//Sum all values later divide by the number of elements
$stats['avg'] = $stats['avg'] + $item;
//Get minimum
if ($stats['min'] == null) {
$stats['min'] = $item;
} else if ($item < $stats['min']) {
$stats['min'] = $item;
}
//Get maximum
if ($stats['max'] == null) {
$stats['max'] = $item;
} else if ($item > $stats['max']) {
$stats['max'] = $item;
}
$count++;
//Get last data
if ($count == $size) {
$stats['last'] = $item;
}
}
//End the calculus for average
if ($count > 0) {
$stats['avg'] = $stats['avg'] / $count;
}
//Format stat data to display properly
$stats['last'] = round($stats['last'], 2);
$stats['avg'] = round($stats['avg'], 2);
$stats['min'] = round($stats['min'], 2);
$stats['max'] = round($stats['max'], 2);
return $stats;
}
function get_statwin_graph_statistics ($chart_array, $series_suffix = '') {
/// IMPORTANT!
///
/// The calculus for AVG, MIN and MAX values are in this function
@ -93,9 +34,70 @@ function get_statwin_graph_statistics ($chart_array, $series_suffix = '') {
/// function to get coherent data between stats and graph visualization
$stats = array ();
$count = 0;
$size = sizeof($chart_array);
//Initialize stats array
$stats = array ("avg" => 0, "min" => null, "max" => null, "last" => 0);
foreach ($chart_array as $item) {
//Sum all values later divide by the number of elements
$stats['avg'] = $stats['avg'] + $item;
//Get minimum
if ($stats['min'] == null) {
$stats['min'] = $item;
}
else if ($item < $stats['min']) {
$stats['min'] = $item;
}
//Get maximum
if ($stats['max'] == null) {
$stats['max'] = $item;
}
else if ($item > $stats['max']) {
$stats['max'] = $item;
}
$count++;
//Get last data
if ($count == $size) {
$stats['last'] = $item;
}
}
//End the calculus for average
if ($count > 0) {
$stats['avg'] = $stats['avg'] / $count;
}
//Format stat data to display properly
$stats['last'] = round($stats['last'], 2);
$stats['avg'] = round($stats['avg'], 2);
$stats['min'] = round($stats['min'], 2);
$stats['max'] = round($stats['max'], 2);
return $stats;
}
function get_statwin_graph_statistics ($chart_array, $series_suffix = '') {
/// IMPORTANT!
///
/// The calculus for AVG, MIN and MAX values are in this function
/// because it must be done based on graph array data not using reporting
/// function to get coherent data between stats and graph visualization
$stats = array ();
$count = 0;
$size = sizeof($chart_array);
//Initialize stats array
@ -1334,14 +1336,16 @@ function graph_event_module ($width = 300, $height = 200, $id_agent) {
switch ($config["dbtype"]) {
case "mysql":
case "postgresql":
$sql = sprintf ('SELECT COUNT(id_evento) as count_number, nombre
$sql = sprintf ('SELECT COUNT(id_evento) AS count_number,
nombre
FROM tevento, tagente_modulo
WHERE id_agentmodule = id_agente_modulo
AND disabled = 0 AND tevento.id_agente = %d
GROUP BY id_agentmodule, nombre LIMIT %d', $id_agent, $max_items);
break;
case "oracle":
$sql = sprintf ('SELECT COUNT(id_evento) as count_number, dbms_lob.substr(nombre,4000,1) as nombre
$sql = sprintf ('SELECT COUNT(id_evento) AS count_number,
dbms_lob.substr(nombre,4000,1) AS nombre
FROM tevento, tagente_modulo
WHERE (id_agentmodule = id_agente_modulo
AND disabled = 0 AND tevento.id_agente = %d) AND rownum <= %d
@ -1358,13 +1362,16 @@ function graph_event_module ($width = 300, $height = 200, $id_agent) {
return;
}
foreach ($events as $event) {
$data[$event['nombre'].' ('.$event['count_number'].')'] = $event["count_number"];
$key = io_safe_output($event['nombre']) .
' ('.$event['count_number'].')';
$data[$key] = $event["count_number"];
}
/* System events */
$sql = "SELECT COUNT(*) FROM tevento WHERE id_agentmodule = 0 AND id_agente = $id_agent";
$sql = "SELECT COUNT(*)
FROM tevento
WHERE id_agentmodule = 0 AND id_agente = $id_agent";
$value = db_get_sql ($sql);
if ($value > 0) {
$data[__('System').' ('.$value.')'] = $value;
@ -1376,7 +1383,7 @@ function graph_event_module ($width = 300, $height = 200, $id_agent) {
return pie3d_graph($config['flash_charts'], $data, $width, $height, __("other"),
'', $water_mark,
$config['fontpath'], $config['font_size']);
$config['fontpath'], $config['font_size'], 1, "bottom");
}
function progress_bar($progress, $width, $height, $title = '', $mode = 1, $value_text = false, $color = false, $options = false) {

View File

@ -434,26 +434,29 @@ function hbar_graph($flash_chart, $chart_data, $width, $height, $color = array()
}
function pie3d_graph($flash_chart, $chart_data, $width, $height,
$others_str = "other", $homedir="", $water_mark = "", $font = '', $font_size = '', $ttl = 1) {
$others_str = "other", $homedir="", $water_mark = "", $font = '',
$font_size = '', $ttl = 1, $legend_position = false) {
return pie_graph('3d', $flash_chart, $chart_data, $width, $height,
$others_str, $homedir, $water_mark, $font, $font_size, $ttl);
$others_str, $homedir, $water_mark, $font, $font_size, $ttl, $legend_position);
}
function pie2d_graph($flash_chart, $chart_data, $width, $height,
$others_str = "other", $homedir="", $water_mark = "", $font = '', $font_size = '', $ttl = 1) {
$others_str = "other", $homedir="", $water_mark = "", $font = '',
$font_size = '', $ttl = 1, $legend_position = false) {
return pie_graph('2d', $flash_chart, $chart_data, $width, $height,
$others_str, $homedir, $water_mark, $font, $font_size, $ttl);
$others_str, $homedir, $water_mark, $font, $font_size, $ttl, $legend_position);
}
function pie_graph($graph_type, $flash_chart, $chart_data, $width, $height,
$others_str = "other", $homedir="", $water_mark = "", $font = '', $font_size = '', $ttl = 1) {
$others_str = "other", $homedir="", $water_mark = "", $font = '',
$font_size = '', $ttl = 1, $legend_position = false) {
setup_watermark($water_mark, $water_mark_file, $water_mark_url);
// This library allows only 8 colors
$max_values = 8;
if(count($chart_data) > $max_values) {
if (count($chart_data) > $max_values) {
$chart_data_trunc = array();
$n = 1;
foreach($chart_data as $key => $value) {
@ -472,9 +475,13 @@ function pie_graph($graph_type, $flash_chart, $chart_data, $width, $height,
}
if ($flash_chart) {
return flot_pie_chart(array_values($chart_data), array_keys($chart_data), $width, $height, $water_mark_url, $font, $font_size);
return flot_pie_chart(array_values($chart_data),
array_keys($chart_data), $width, $height, $water_mark_url,
$font, $font_size, $legend_position);
}
else {
//TODO SET THE LEGEND POSITION
$graph = array();
$graph['data'] = $chart_data;
$graph['width'] = $width;

View File

@ -3,10 +3,10 @@
*/
function pandoraFlotPie(graph_id, values, labels, nseries, width, font_size, water_mark, separator) {
function pandoraFlotPie(graph_id, values, labels, nseries, width, font_size, water_mark, separator, legend_position, height) {
var labels = labels.split(separator);
var data = values.split(separator);
for( var i = 0; i<nseries; i++)
{
data[i] = { label: labels[i], data: parseInt(data[i]) }
@ -14,7 +14,7 @@ function pandoraFlotPie(graph_id, values, labels, nseries, width, font_size, wat
var label_conf;
if(width < 400) {
if (width < 400) {
label_conf = {
show: false
};
@ -33,12 +33,12 @@ function pandoraFlotPie(graph_id, values, labels, nseries, width, font_size, wat
};
}
var plot = $.plot($('#'+graph_id), data,
{
var conf_pie = {
series: {
pie: {
show: true,
radius: 3/4,
//offset: {top: -100},
label: label_conf
//$label_str
}
@ -50,7 +50,26 @@ function pandoraFlotPie(graph_id, values, labels, nseries, width, font_size, wat
hoverable: true,
clickable: true
}
});
};
switch (legend_position) {
case 'bottom':
if (width > height)
offset = - (height / 5);
else
offset = - (width / 5);
conf_pie.series.pie.radius = 1 / 2.5;
conf_pie.series.pie.offset =
conf_pie.series.pie.offset = {top: offset};
conf_pie.legend.position = "s";
break;
case 'right':
default:
//TODO FOR TOP OR LEFT OR RIGHT
break;
}
var plot = $.plot($('#'+graph_id), data, conf_pie);
var legends = $('#'+graph_id+' .legendLabel');
legends.each(function () {
@ -58,22 +77,22 @@ function pandoraFlotPie(graph_id, values, labels, nseries, width, font_size, wat
$(this).css('width', $(this).width()+5);
$(this).css('font-size', font_size+'pt');
});
// Events
$('#'+graph_id).bind('plothover', pieHover);
$('#'+graph_id).bind('plotclick', pieClick);
$('#'+graph_id).bind('mouseout',resetInteractivity);
function pieHover(event, pos, obj)
{
if (!obj)
return;
index = obj.seriesIndex;
legends.css('font-weight', '');
legends.eq(index).css('font-weight', 'bold');
}
// Reset styles
function resetInteractivity() {
legends.each(function () {
@ -443,10 +462,10 @@ function pandoraFlotSlicebar(graph_id, values, datacolor, labels, legend, acumul
}
function pandoraFlotArea(graph_id, values, labels, labels_long, legend, colors, type, serie_types, water_mark, width, max_x, homeurl, unit, font_size, menu, events, event_ids, legend_events, alerts, alert_ids, legend_alerts, yellow_threshold, red_threshold, force_integer, separator, separator2, series_suffix_str) {
var threshold = true;
var thresholded = false;
values = values.split(separator2);
serie_types = serie_types.split(separator);
labels_long = labels_long.split(separator);

View File

@ -314,7 +314,9 @@ function flot_area_graph($chart_data, $width, $height, $color, $legend, $long_in
///////////////////////////////
// Prints a FLOT pie chart
function flot_pie_chart ($values, $labels, $width, $height, $water_mark, $font = '', $font_size = 8) {
function flot_pie_chart ($values, $labels, $width, $height, $water_mark,
$font = '', $font_size = 8, $legend_position = '') {
include_javascript_dependencies_flot_graph();
$series = sizeof($values);
@ -324,6 +326,16 @@ function flot_pie_chart ($values, $labels, $width, $height, $water_mark, $font =
$graph_id = uniqid('graph_');
switch ($legend_position) {
case 'bottom':
$height = $height + (count($values) * 24);
break;
case 'right':
default:
//TODO FOR TOP OR LEFT OR RIGHT
break;
}
$return = "<div id='$graph_id' class='graph' style='width: ".$width."px; height: ".$height."px;'></div>";
if($water_mark != '') {
@ -341,7 +353,9 @@ function flot_pie_chart ($values, $labels, $width, $height, $water_mark, $font =
$return .= "<script type='text/javascript'>";
$return .= "pandoraFlotPie('$graph_id', '$values', '$labels', '$series', '$width', $font_size, $water_mark, '$separator')";
$return .= "pandoraFlotPie('$graph_id', '$values', '$labels',
'$series', '$width', $font_size, $water_mark,
'$separator', '$legend_position', '$height')";
$return .= "</script>";

View File

@ -39,7 +39,7 @@ if ($agent === false) {
$is_extra = enterprise_hook('policies_is_agent_extra_policy', array($id_agente));
if($is_extra === ENTERPRISE_NOT_HOOK) {
if ($is_extra === ENTERPRISE_NOT_HOOK) {
$is_extra = false;
}
@ -57,7 +57,7 @@ echo '<div style="height: 10px">&nbsp;</div>';
//Floating div
echo '<div id="agent_access" style="float:right; width:320px; padding-top:10px;">';
if ($config["agentaccess"]){
if ($config["agentaccess"]) {
echo '<b>'.__('Agent access rate (24h)').'</b><br />';
graphic_agentaccess($id_agente, 280, 110, 86400);
@ -132,7 +132,7 @@ echo '<td class="datos2" colspan="2"><a href="index.php?sec=estado&amp;sec2=oper
// Agent Interval
echo '<tr><td class="datos"><b>'.__('Interval').'</b></td>';
echo '<td class="datos" colspan="2">'.human_time_description_raw ($agent["intervalo"]).'</td></tr>';
// Comments
echo '<tr><td class="datos2"><b>'.__('Description').'</b></td>';
echo '<td class="datos2" colspan="2">'.$agent["comentarios"].'</td></tr>';
@ -172,7 +172,7 @@ if ($config['activate_gis']) {
}
// If the url description is setted
if ($agent['url_address'] != ''){
if ($agent['url_address'] != '') {
echo '<tr><td class="datos"><b>'.__('Url address').'</b></td>';
echo '<td class="datos2" colspan="2"><a href='.$agent["url_address"].'>' . $agent["url_address"] . '</a></td></tr>';
}
@ -208,10 +208,10 @@ if ($fields === false) {
$fields = array ();
}
if ($fields)
foreach($fields as $field) {
foreach ($fields as $field) {
echo '<tr><td class="datos"><b>'.$field['name'] . ui_print_help_tip (__('Custom field'), true).'</b></td>';
$custom_value = db_get_value_filter('description', 'tagent_custom_data', array('id_field' => $field['id_field'], 'id_agent' => $id_agente));
if($custom_value === false || $custom_value == '') {
if ($custom_value === false || $custom_value == '') {
$custom_value = '<i>-'.__('empty').'-</i>';
}
echo '<td class="datos f9" colspan="2">'.$custom_value.'</td></tr>';