2012-03-08 Sergio Martin <sergio.martin@artica.es>

* include/functions_graph.php
	include/graphs/functions_flot.php
	include/graphs/flot/pandora.flot.js
	include/graphs/fgraph.php
	operation/agentes/stat_win.php: Adapted events slice graph to
	the sparse/boolean/string graph. Fix some bugs on menu and legend 
	graphs



git-svn-id: https://svn.code.sf.net/p/pandora/code/trunk@5721 c3f86ba8-e40f-0410-aaad-9ba5e7f4b01f
This commit is contained in:
zarzuelo 2012-03-08 12:32:59 +00:00
parent 971687744e
commit 4fa4605ca0
6 changed files with 117 additions and 55 deletions

View File

@ -1,3 +1,13 @@
2012-03-08 Sergio Martin <sergio.martin@artica.es>
* include/functions_graph.php
include/graphs/functions_flot.php
include/graphs/flot/pandora.flot.js
include/graphs/fgraph.php
operation/agentes/stat_win.php: Adapted events slice graph to
the sparse/boolean/string graph. Fix some bugs on menu and legend
graphs
2012-03-07 Miguel de Dios <miguel.dedios@artica.es>
* godmode/alerts/alert_list.builder.php,

View File

@ -29,7 +29,7 @@ function grafico_modulo_sparse ($agent_module_id, $period, $show_events,
$width, $height , $title = '', $unit_name = null,
$show_alerts = false, $avg_only = 0, $pure = false,
$date = 0, $unit = '', $baseline = 0, $return_data = 0, $show_title = true,
$only_image = false, $homeurl = '', $ttl = 1, $projection = false) {
$only_image = false, $homeurl = '', $ttl = 1, $projection = false, $adapt_key = '') {
global $config;
global $graphic_type;
@ -388,7 +388,7 @@ function grafico_modulo_sparse ($agent_module_id, $period, $show_events,
$long_index, "images/image_problem.opaque.png", "", "", $homeurl,
$water_mark,
$config['fontpath'], $config['font_size'], $unit, $ttl, $series_type,
$chart_extra_data, $warning_min, $critical_min);
$chart_extra_data, $warning_min, $critical_min, $adapt_key);
}
function graph_get_formatted_date($timestamp, $format1, $format2) {
@ -1729,7 +1729,7 @@ function fs_error_image () {
function grafico_modulo_boolean ($agent_module_id, $period, $show_events,
$width, $height , $title, $unit_name, $show_alerts, $avg_only = 0, $pure=0,
$date = 0, $only_image = false, $homeurl = '') {
$date = 0, $only_image = false, $homeurl = '', $adapt_key) {
global $config;
global $graphic_type;
@ -2028,7 +2028,8 @@ function grafico_modulo_boolean ($agent_module_id, $period, $show_events,
return area_graph($flash_chart, $chart, $width, $height, $color, $legend,
$long_index, "images/image_problem.opaque.png", "", $unit, $homeurl,
$water_mark,
$config['fontpath'], $config['font_size'], $unit);
$config['fontpath'], $config['font_size'], $unit, 1, array(),
array(), 0, 0, $adapt_key);
}
@ -2206,7 +2207,7 @@ function graph_netflow_aggregate_pie ($data, $aggregate) {
*/
function grafico_modulo_string ($agent_module_id, $period, $show_events,
$width, $height , $title, $unit_name, $show_alerts, $avg_only = 0, $pure=0,
$date = 0, $only_image = false, $homeurl = '') {
$date = 0, $only_image = false, $homeurl = '', $adapt_key) {
global $config;
global $graphic_type;
@ -2415,7 +2416,7 @@ function grafico_modulo_string ($agent_module_id, $period, $show_events,
return vbar_graph($flash_chart, $chart, $width, $height, $color,
$legend, "", $unit, $homeurl,
$water_mark,
$config['fontpath'], $config['font_size'], true, true, 1, true);
$config['fontpath'], $config['font_size'], true, 1, true, $adapt_key);
}
function grafico_modulo_log4x ($id_agente_modulo, $periodo, $show_event,
@ -2793,8 +2794,9 @@ function grafico_modulo_log4x_format_y_axis ( $number , $decimals=2, $dec_point=
* @param integer period time period
* @param string homeurl Home url if the complete path is needed
* @param int Zoom factor over the graph
* @param string adaptation width and margin left key (could be adapter_[something] or adapted_[something])
*/
function graphic_module_events ($id_module, $width, $height, $period = 0, $homeurl = '', $zoom = 0) {
function graphic_module_events ($id_module, $width, $height, $period = 0, $homeurl = '', $zoom = 0, $adapt_key = '') {
global $config;
global $graphic_type;
@ -2882,7 +2884,7 @@ function graphic_module_events ($id_module, $width, $height, $period = 0, $homeu
// Draw slicebar graph
if($config['flash_charts']) {
echo flot_slicesbar_graph($data, $period, $width, 15, $legend, $colors, $config['fontpath'], $config['round_corner'], $homeurl);
echo flot_slicesbar_graph($data, $period, $width, 15, $legend, $colors, $config['fontpath'], $config['round_corner'], $homeurl, '', $adapt_key);
}
else {
echo slicesbar_graph($data, $period, $width, 15, $colors, $config['fontpath'], $config['round_corner'], $homeurl);

View File

@ -182,12 +182,13 @@ function slicesbar_graph($chart_data, $period, $width, $height, $colors, $font,
function vbar_graph($flash_chart, $chart_data, $width, $height, $color = array(),
$legend = array(), $xaxisname = "", $yaxisname = "", $homedir="",
$water_mark = '', $font = '', $font_size = '', $force_steps = true, $ttl = 1, $reduce_data_columns = false) {
$water_mark = '', $font = '', $font_size = '', $force_steps = true, $ttl = 1, $reduce_data_columns = false,
$adapt_key) {
setup_watermark($water_mark, $water_mark_file, $water_mark_url);
if($flash_chart) {
return flot_vcolumn_chart ($chart_data, $width, $height, $color, $legend, $long_index, $homeurl, $unit, $water_mark_url, $homedir, $reduce_data_columns);
return flot_vcolumn_chart ($chart_data, $width, $height, $color, $legend, $long_index, $homeurl, $unit, $water_mark_url, $homedir, $reduce_data_columns, $adapt_key);
}
else {
$graph = array();
@ -209,6 +210,7 @@ function vbar_graph($flash_chart, $chart_data, $width, $height, $color = array()
}
}
// NOT USED ACTUALLY
function threshold_graph($flash_chart, $chart_data, $width, $height, $ttl = 1) {
if($flash_chart) {
return flot_area_simple_graph($chart_data, $width, $height);
@ -221,7 +223,7 @@ function threshold_graph($flash_chart, $chart_data, $width, $height, $ttl = 1) {
function area_graph($flash_chart, $chart_data, $width, $height, $color, $legend,
$long_index, $no_data_image, $xaxisname = "", $yaxisname = "", $homeurl="",
$water_mark = "", $font = '', $font_size = '', $unit = '', $ttl = 1, $series_type = array(),
$chart_extra_data = array(), $yellow_threshold = 0, $red_threshold = 0) {
$chart_extra_data = array(), $yellow_threshold = 0, $red_threshold = 0, $adapt_key = '') {
setup_watermark($water_mark, $water_mark_file, $water_mark_url);
@ -235,7 +237,7 @@ function area_graph($flash_chart, $chart_data, $width, $height, $color, $legend,
}
if($flash_chart) {
return flot_area_simple_graph($chart_data, $width, $height, $color, $legend, $long_index, $homeurl, $unit, $water_mark_url, $series_type, $chart_extra_data, $yellow_threshold, $red_threshold);
return flot_area_simple_graph($chart_data, $width, $height, $color, $legend, $long_index, $homeurl, $unit, $water_mark_url, $series_type, $chart_extra_data, $yellow_threshold, $red_threshold, $adapt_key);
}
else {
$graph = array();

View File

@ -241,7 +241,7 @@ function pandoraFlotVBars(graph_id, values, labels, labels_long, legend, colors,
});
}
labels = labels.split(separator).reverse();
labels = labels.split(separator);
var stack = 0, bars = true, lines = false, steps = false;
@ -356,6 +356,9 @@ function pandoraFlotSlicebar(graph_id, values, datacolor, labels, legend, acumul
acumulate_data = acumulate_data.split(separator);
datacolor = datacolor.split(separator);
// Check possible adapt_keys on classes
check_adaptions(graph_id);
var datas = new Array();
for(i=0;i<values.length;i++) {
@ -402,6 +405,33 @@ function pandoraFlotSlicebar(graph_id, values, datacolor, labels, legend, acumul
var plot = $.plot($('#'+graph_id), datas, options );
// Events
$('#'+graph_id).bind('plothover', function (event, pos, item) {
if(item) {
var from = legend[item.seriesIndex];
var to = legend[item.seriesIndex+1];
if(to == undefined) {
to = '>';
}
$('#extra_'+graph_id).text(from+'-'+to);
var extra_height = parseInt($('#extra_'+graph_id).css('height').split('px')[0]);
var extra_width = parseInt($('#extra_'+graph_id).css('width').split('px')[0]);
$('#extra_'+graph_id).css('left',pos.pageX-(extra_width/2)+'px');
$('#extra_'+graph_id).css('top',plot.offset().top-extra_height-5+'px');
$('#extra_'+graph_id).show();
}
});
$('#'+graph_id).bind('mouseout',resetInteractivity);
// Reset interactivity styles
function resetInteractivity() {
$('#extra_'+graph_id).hide();
}
// Format functions
function xFormatter(v, axis) {
for(i = 0; i < acumulate_data.length; i++) {
@ -606,14 +636,9 @@ function pandoraFlotArea(graph_id, values, labels, labels_long, legend, colors,
var plot = $.plot($('#'+graph_id), datas, options);
// Adjust the overview plot to the width and position of the main plot
yAxisWidth = $('#'+graph_id+' .yAxis .tickLabel').css('width');
adjust_left_width_canvas(graph_id, 'overview_'+graph_id);
overview_pix = $('#overview_'+graph_id).css('width').split('px');
new_overview_width = parseInt(overview_pix[0])-parseInt(yAxisWidth);
$('#overview_'+graph_id).css('width',new_overview_width);
$('#overview_'+graph_id).css('margin-left',yAxisWidth);
// Adjust linked graph to the width and position of the main plot
// Miniplot
var overview = $.plot($('#overview_'+graph_id),datas, {
@ -906,6 +931,10 @@ function pandoraFlotArea(graph_id, values, labels, labels_long, legend, colors,
// Adjust the menu image on top of the plot
$('#menu_overview_'+graph_id)[0].onload = function() {
// If there is no legend we increase top-padding to make space to the menu
if(legends.length == 0) {
$('#menu_'+graph_id).parent().css('padding-top',$('#menu_'+graph_id).css('height'));
}
// Add bottom margin in the legend
var menu_height = parseInt($('#menu_'+graph_id).css('height').split('px')[0]);
var legend_margin_bottom = parseInt($('#legend_'+graph_id).css('margin-bottom').split('px')[0]);
@ -987,3 +1016,26 @@ function get_event_details (event_ids) {
return table;
}
function adjust_left_width_canvas(adapter_id, adapted_id) {
adapter_left_margin = $('#'+adapter_id+' .yAxis .tickLabel').css('width');
adapted_pix = $('#'+adapted_id).css('width').split('px');
new_adapted_width = parseInt(adapted_pix[0])-parseInt(adapter_left_margin);
$('#'+adapted_id).css('width',new_adapted_width);
$('#'+adapted_id).css('margin-left',adapter_left_margin);
}
function check_adaptions(graph_id) {
var classes = $('#'+graph_id).attr('class').split(' ');
$.each(classes, function(i,v) {
// If has a class starting with adapted, we adapt it
if(v.split('_')[0] == 'adapted') {
var adapter_id = $('.adapter_'+v.split('_')[1]).attr('id');
adjust_left_width_canvas(adapter_id, graph_id);
}
});
}

View File

@ -77,39 +77,31 @@ function include_javascript_dependencies_flot_graph($return = false) {
///////////////////////////////
////////// AREA GRAPHS ////////
///////////////////////////////
function flot_area_stacked_graph($chart_data, $width, $height, $color, $legend, $long_index, $homeurl = '', $unit = '', $water_mark = '', $serie_types = array(), $chart_extra_data = array(), $yellow_threshold = '', $red_threshold = '') {
function flot_area_stacked_graph($chart_data, $width, $height, $color, $legend, $long_index, $homeurl = '', $unit = '', $water_mark = '', $serie_types = array(), $chart_extra_data = array(), $yellow_threshold = 0, $red_threshold = 0, $adapt_key= '') {
global $config;
include_javascript_dependencies_flot_graph();
return flot_area_graph($chart_data, $width, $height, $color, $legend, $long_index, $homeurl, $unit, 'area_stacked', $water_mark, $serie_types, $chart_extra_data, $yellow_threshold, $red_threshold);
return flot_area_graph($chart_data, $width, $height, $color, $legend, $long_index, $homeurl, $unit, 'area_stacked', $water_mark, $serie_types, $chart_extra_data, $yellow_threshold, $red_threshold, $adapt_key);
}
function flot_area_simple_graph($chart_data, $width, $height, $color, $legend, $long_index, $homeurl = '', $unit = '', $water_mark = '', $serie_types = array(), $chart_extra_data = array(), $yellow_threshold = '', $red_threshold = '') {
function flot_area_simple_graph($chart_data, $width, $height, $color, $legend, $long_index, $homeurl = '', $unit = '', $water_mark = '', $serie_types = array(), $chart_extra_data = array(), $yellow_threshold = 0, $red_threshold = 0, $adapt_key= '') {
global $config;
include_javascript_dependencies_flot_graph();
return flot_area_graph($chart_data, $width, $height, $color, $legend, $long_index, $homeurl, $unit, 'area_simple', $water_mark, $serie_types, $chart_extra_data, $yellow_threshold, $red_threshold);
return flot_area_graph($chart_data, $width, $height, $color, $legend, $long_index, $homeurl, $unit, 'area_simple', $water_mark, $serie_types, $chart_extra_data, $yellow_threshold, $red_threshold, $adapt_key);
}
function flot_line_stacked_graph($chart_data, $width, $height, $color, $legend, $long_index, $homeurl = '', $unit = '', $water_mark = '', $serie_types = array(), $chart_extra_data = array(), $yellow_threshold = '', $red_threshold = '') {
function flot_line_stacked_graph($chart_data, $width, $height, $color, $legend, $long_index, $homeurl = '', $unit = '', $water_mark = '', $serie_types = array(), $chart_extra_data = array(), $yellow_threshold = 0, $red_threshold = 0, $adapt_key= '') {
global $config;
include_javascript_dependencies_flot_graph();
return flot_area_graph($chart_data, $width, $height, $color, $legend, $long_index, $homeurl, $unit, 'line_stacked', $water_mark, $serie_types, $chart_extra_data, $yellow_threshold, $red_threshold);
return flot_area_graph($chart_data, $width, $height, $color, $legend, $long_index, $homeurl, $unit, 'line_stacked', $water_mark, $serie_types, $chart_extra_data, $yellow_threshold, $red_threshold, $adapt_key);
}
function flot_line_simple_graph($chart_data, $width, $height, $color, $legend, $long_index, $homeurl = '', $unit = '', $water_mark = '', $serie_types = array(), $chart_extra_data = array(), $yellow_threshold = '', $red_threshold = '') {
function flot_line_simple_graph($chart_data, $width, $height, $color, $legend, $long_index, $homeurl = '', $unit = '', $water_mark = '', $serie_types = array(), $chart_extra_data = array(), $yellow_threshold = 0, $red_threshold = 0, $adapt_key= '') {
global $config;
include_javascript_dependencies_flot_graph();
return flot_area_graph($chart_data, $width, $height, $color, $legend, $long_index, $homeurl, $unit, 'line_simple', $water_mark, $serie_types, $chart_extra_data, $yellow_threshold, $red_threshold);
return flot_area_graph($chart_data, $width, $height, $color, $legend, $long_index, $homeurl, $unit, 'line_simple', $water_mark, $serie_types, $chart_extra_data, $yellow_threshold, $red_threshold, $adapt_key);
}
function flot_area_graph($chart_data, $width, $height, $color, $legend, $long_index, $homeurl, $unit, $type, $water_mark, $serie_types, $chart_extra_data, $yellow_threshold, $red_threshold) {
function flot_area_graph($chart_data, $width, $height, $color, $legend, $long_index, $homeurl, $unit, $type, $water_mark, $serie_types, $chart_extra_data, $yellow_threshold, $red_threshold, $adapt_key) {
global $config;
include_javascript_dependencies_flot_graph();
@ -124,7 +116,7 @@ function flot_area_graph($chart_data, $width, $height, $color, $legend, $long_in
$return = "<div>";
// Set some containers to legend, graph, timestamp tooltip, etc.
$return .= "<p id='legend_$graph_id' style='font-size:".$font_size."pt'></p>";
$return .= "<div id='$graph_id' class='graph' style='width: ".$width."px; height: ".$height."px;'></div>";
$return .= "<div id='$graph_id' class='graph $adapt_key' style='width: ".$width."px; height: ".$height."px;'></div>";
$return .= "<div id='overview_$graph_id' style='display:none; margin-left:0px; margin-top:20px; width: ".$width."px; height:50px;'></div>";
$return .= "<div id='timestamp_$graph_id' style='font-size:".$font_size."pt;display:none; position:absolute; background:#fff; border: solid 1px #aaa; padding: 2px'></div>";
@ -211,7 +203,7 @@ function flot_area_graph($chart_data, $width, $height, $color, $legend, $long_in
if($menu) {
$threshold = false;
if($yellow_threshold != '' && $red_threshold != '') {
if($yellow_threshold != 0 || $red_threshold != 0) {
$threshold = true;
}
@ -431,7 +423,7 @@ function flot_hcolumn_chart ($graph_data, $width, $height, $water_mark) {
}
// Returns a 3D column chart
function flot_vcolumn_chart ($graph_data, $width, $height, $color, $legend, $long_index, $homeurl, $unit, $water_mark, $homedir, $reduce_data_columns) {
function flot_vcolumn_chart ($graph_data, $width, $height, $color, $legend, $long_index, $homeurl, $unit, $water_mark, $homedir, $reduce_data_columns, $adapt_key) {
global $config;
include_javascript_dependencies_flot_graph();
@ -444,7 +436,7 @@ function flot_vcolumn_chart ($graph_data, $width, $height, $color, $legend, $lon
$graph_id2 = uniqid('graph_');
// Set some containers to legend, graph, timestamp tooltip, etc.
$return .= "<div id='$graph_id' class='graph' style='width: ".$width."px; height: ".$height."px;'></div>";
$return .= "<div id='$graph_id' class='graph $adapt_key' style='width: ".$width."px; height: ".$height."px;'></div>";
$return .= "<div id='value_$graph_id' style='display:none; position:absolute; background:#fff; border: solid 1px #aaa; padding: 2px'></div>";
if($water_mark != '') {
@ -536,7 +528,7 @@ function flot_vcolumn_chart ($graph_data, $width, $height, $color, $legend, $lon
return $return;
}
function flot_slicesbar_graph ($graph_data, $period, $width, $height, $legend, $colors, $fontpath, $round_corner, $homeurl, $watermark = '') {
function flot_slicesbar_graph ($graph_data, $period, $width, $height, $legend, $colors, $fontpath, $round_corner, $homeurl, $watermark = '', $adapt_key = '') {
global $config;
include_javascript_dependencies_flot_graph();
@ -549,7 +541,7 @@ function flot_slicesbar_graph ($graph_data, $period, $width, $height, $legend, $
$graph_id = uniqid('graph_');
// Set some containers to legend, graph, timestamp tooltip, etc.
$return = "<div id='$graph_id' class='graph' style='width: ".$width."px; height: ".$height."px;'></div>";
$return = "<div id='$graph_id' class='graph $adapt_key' style='width: ".$width."px; height: ".$height."px;'></div>";
$return .= "<div id='value_$graph_id' style='display:none; position:absolute; background:#fff; border: solid 1px #aaa; padding: 2px'></div>";
// Set a weird separator to serialize and unserialize passing data from php to javascript
@ -578,6 +570,10 @@ function flot_slicesbar_graph ($graph_data, $period, $width, $height, $legend, $
$fontsize = 7;
$extra_height = 15;
$return .= "<div id='extra_$graph_id' style='font-size: ".$fontsize."pt; display:none; position:absolute; overflow: auto; height: ".$extra_height."px; background:#fff; padding: 2px 2px 2px 2px; border: solid #000 1px;'></div>";
$maxticks = (int) ($width / ($fontsize * $leg_max_length));
$i_aux = $i;

View File

@ -167,29 +167,29 @@ echo "<div style='margin-left:20px'>";
switch ($graph_type) {
case 'boolean':
echo grafico_modulo_boolean ($id, $period, $draw_events, $width, $height,
$label, null, $draw_alerts, $avg_only, false, $date, false, $urlImage);
$label, null, $draw_alerts, $avg_only, false, $date, false, $urlImage, 'adapter_'.$graph_type);
echo '<br><br><br>';
if ($show_events_graph)
echo graphic_module_events($id, $width, $height, $period, $config['homeurl'] . '/', $zoom);
echo graphic_module_events($id, $width, $height, $period, $config['homeurl'] . '/', $zoom, 'adapted_'.$graph_type);
break;
case 'sparse':
echo grafico_modulo_sparse ($id, $period, $draw_events, $width, $height,
$label, null, $draw_alerts, $avg_only, false, $date, '', $baseline,
0, true, false, $urlImage);
0, true, false, $urlImage, 1, false, 'adapter_'.$graph_type);
echo '<br><br><br>';
if ($show_events_graph)
echo graphic_module_events($id, $width, $height, $period, $config['homeurl'] . '/', $zoom);
echo graphic_module_events($id, $width, $height, $period, $config['homeurl'] . '/', $zoom, 'adapted_'.$graph_type);
break;
case 'string':
echo grafico_modulo_string ($id, $period, $draw_events, $width, $height,
$label, null, $draw_alerts, 1, false, $date, false, $urlImage);
$label, null, $draw_alerts, 1, false, $date, false, $urlImage, 'adapter_'.$graph_type);
echo '<br><br><br>';
if ($show_events_graph)
echo graphic_module_events($id, $width, $height, $period, $config['homeurl'] . '/', $zoom);
echo graphic_module_events($id, $width, $height, $period, $config['homeurl'] . '/', $zoom, 'adapted_'.$graph_type);
break;
case 'log4x':
echo grafico_modulo_log4x ($id, $period, $draw_events, $width, $height,
$label, $unit_name, $draw_alerts, 1, $pure, $date, 1);
$label, $unit_name, $draw_alerts, 1, $pure, $date);
echo '<br><br><br>';
if ($show_events_graph)
echo graphic_module_events($id, $width, $height, $period, $config['homeurl'] . '/', $zoom);