diff --git a/pandora_console/ChangeLog b/pandora_console/ChangeLog index 334691fc01..ab4cf5dd41 100644 --- a/pandora_console/ChangeLog +++ b/pandora_console/ChangeLog @@ -1,3 +1,13 @@ +2013-01-30 Miguel de Dios + + * 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 * extras/pandoradb_migrate_4.0.x_to_5.0.mysql.sql diff --git a/pandora_console/include/functions_graph.php b/pandora_console/include/functions_graph.php index a8c708adbf..69d2362787 100755 --- a/pandora_console/include/functions_graph.php +++ b/pandora_console/include/functions_graph.php @@ -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) { diff --git a/pandora_console/include/graphs/fgraph.php b/pandora_console/include/graphs/fgraph.php index 4017fc0f86..f38cad7ea3 100755 --- a/pandora_console/include/graphs/fgraph.php +++ b/pandora_console/include/graphs/fgraph.php @@ -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; diff --git a/pandora_console/include/graphs/flot/pandora.flot.js b/pandora_console/include/graphs/flot/pandora.flot.js index 04534c1dcf..d4a758150d 100644 --- a/pandora_console/include/graphs/flot/pandora.flot.js +++ b/pandora_console/include/graphs/flot/pandora.flot.js @@ -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 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); diff --git a/pandora_console/include/graphs/functions_flot.php b/pandora_console/include/graphs/functions_flot.php index 6f496f3277..9f7f07004c 100644 --- a/pandora_console/include/graphs/functions_flot.php +++ b/pandora_console/include/graphs/functions_flot.php @@ -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 = "
"; if($water_mark != '') { @@ -341,7 +353,9 @@ function flot_pie_chart ($values, $labels, $width, $height, $water_mark, $font = $return .= ""; diff --git a/pandora_console/operation/agentes/estado_generalagente.php b/pandora_console/operation/agentes/estado_generalagente.php index 4a5aa7eff9..3ce3879b78 100644 --- a/pandora_console/operation/agentes/estado_generalagente.php +++ b/pandora_console/operation/agentes/estado_generalagente.php @@ -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 '
 
'; //Floating div echo '
'; -if ($config["agentaccess"]){ +if ($config["agentaccess"]) { echo ''.__('Agent access rate (24h)').'
'; graphic_agentaccess($id_agente, 280, 110, 86400); @@ -132,7 +132,7 @@ echo ''.__('Interval').''; echo ''.human_time_description_raw ($agent["intervalo"]).''; - + // Comments echo ''.__('Description').''; echo ''.$agent["comentarios"].''; @@ -172,7 +172,7 @@ if ($config['activate_gis']) { } // If the url description is setted -if ($agent['url_address'] != ''){ +if ($agent['url_address'] != '') { echo ''.__('Url address').''; echo '' . $agent["url_address"] . ''; } @@ -208,10 +208,10 @@ if ($fields === false) { $fields = array (); } if ($fields) -foreach($fields as $field) { +foreach ($fields as $field) { echo ''.$field['name'] . ui_print_help_tip (__('Custom field'), true).''; $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 = '-'.__('empty').'-'; } echo ''.$custom_value.'';