From e3e549cbe8b57b0065edfcf78d239b4d469713a7 Mon Sep 17 00:00:00 2001 From: m-lopez-f Date: Tue, 15 Mar 2016 09:25:48 +0100 Subject: [PATCH] Fixed problems with dashboard performance when include users maps. Tiquet: #3438 --- .../include/ajax/visual_console.ajax.php | 3 +- .../include/functions_custom_graphs.php | 5 +- pandora_console/include/functions_graph.php | 15 +- .../include/functions_visual_map.php | 15 +- pandora_console/include/graphs/fgraph.php | 270 ++++++++++++------ .../include/graphs/flot/pandora.flot.js | 24 +- .../include/graphs/functions_d3.php | 4 +- .../include/graphs/functions_flot.php | 21 +- .../operation/visual_console/render_view.php | 2 +- 9 files changed, 238 insertions(+), 121 deletions(-) diff --git a/pandora_console/include/ajax/visual_console.ajax.php b/pandora_console/include/ajax/visual_console.ajax.php index c927989130..9715ab7ff9 100644 --- a/pandora_console/include/ajax/visual_console.ajax.php +++ b/pandora_console/include/ajax/visual_console.ajax.php @@ -36,13 +36,14 @@ enterprise_include_once('include/functions_visual_map.php'); $id_visual_console = get_parameter('id_visual_console', null); $render_map = (bool)get_parameter('render_map', false); +$graph_javascript = (bool)get_parameter('graph_javascript', false); if ($render_map) { $width = (int)get_parameter('width', '400'); $height = (int)get_parameter('height', '400'); visual_map_print_visual_map($id_visual_console, true, true, $width, - $height); + $height, '', false, $graph_javascript); return; } diff --git a/pandora_console/include/functions_custom_graphs.php b/pandora_console/include/functions_custom_graphs.php index 5d82f997ac..db69a68698 100644 --- a/pandora_console/include/functions_custom_graphs.php +++ b/pandora_console/include/functions_custom_graphs.php @@ -164,7 +164,7 @@ function custom_graphs_print($id_graph, $height, $width, $period, $background_color = 'white', $modules_param = array(), $homeurl = '', $name_list = array(), $unit_list = array(), $show_last = true, $show_max = true, $show_min = true, $show_avg = true, $ttl = 1, - $dashboard = false) { + $dashboard = false, $vconsole = false) { global $config; @@ -243,7 +243,8 @@ function custom_graphs_print($id_graph, $height, $width, $period, $show_min, $show_avg, $labels, - $dashboard); + $dashboard, + $vconsole); if ($return) return $output; diff --git a/pandora_console/include/functions_graph.php b/pandora_console/include/functions_graph.php index 8d4493be5b..38c10cf2c4 100644 --- a/pandora_console/include/functions_graph.php +++ b/pandora_console/include/functions_graph.php @@ -765,7 +765,8 @@ function grafico_modulo_sparse ($agent_module_id, $period, $show_events, $unit = '', $baseline = 0, $return_data = 0, $show_title = true, $only_image = false, $homeurl = '', $ttl = 1, $projection = false, $adapt_key = '', $compare = false, $show_unknown = false, - $menu = true, $backgroundColor = 'white', $percentil = null) { + $menu = true, $backgroundColor = 'white', $percentil = null, + $dashboard = false, $vconsole = false) { global $config; global $graphic_type; @@ -892,7 +893,7 @@ function grafico_modulo_sparse ($agent_module_id, $period, $show_events, $config['font_size'], $unit, $ttl, $series_type, $chart_extra_data, $warning_min, $critical_min, $adapt_key, false, $series_suffix_str, $menu, - $backgroundColor); + $backgroundColor, $dashboard, $vconsole); } } elseif ($config['type_module_charts'] === 'line') { @@ -969,7 +970,7 @@ function graphic_combined_module ($module_list, $weight_list, $period, $only_image = false, $homeurl = '', $ttl = 1, $projection = false, $prediction_period = false, $background_color = 'white', $name_list = array(), $unit_list = array(), $show_last = true, $show_max = true, - $show_min = true, $show_avg = true, $labels = false, $dashboard = false) { + $show_min = true, $show_avg = true, $labels = false, $dashboard = false, $vconsole = false) { global $config; global $graphic_type; @@ -1598,7 +1599,7 @@ function graphic_combined_module ($module_list, $weight_list, $period, ui_get_full_url("images/image_problem.opaque.png", false, false, false), "", "", $homeurl, $water_mark, $config['fontpath'], $fixed_font_size, $unit, $ttl, array(), array(), 0, 0, '', - false, '', true, $background_color,$dashboard); + false, '', true, $background_color,$dashboard, $vconsole); break; default: case CUSTOM_GRAPH_STACKED_AREA: @@ -1606,21 +1607,21 @@ function graphic_combined_module ($module_list, $weight_list, $period, $width, $height, $color, $module_name_list, $long_index, ui_get_full_url("images/image_problem.opaque.png", false, false, false), "", "", $water_mark, $config['fontpath'], $fixed_font_size, - "", $ttl, $homeurl, $background_color,$dashboard); + "", $ttl, $homeurl, $background_color,$dashboard, $vconsole); break; case CUSTOM_GRAPH_LINE: return line_graph($flash_charts, $graph_values, $width, $height, $color, $module_name_list, $long_index, ui_get_full_url("images/image_problem.opaque.png", false, false, false), "", "", $water_mark, $config['fontpath'], $fixed_font_size, - $unit, $ttl, $homeurl, $background_color,$dashboard); + $unit, $ttl, $homeurl, $background_color,$dashboard, $vconsole); break; case CUSTOM_GRAPH_STACKED_LINE: return stacked_line_graph($flash_charts, $graph_values, $width, $height, $color, $module_name_list, $long_index, ui_get_full_url("images/image_problem.opaque.png", false, false, false), "", "", $water_mark, $config['fontpath'], $fixed_font_size, - "", $ttl, $homeurl, $background_color,$dashboard); + "", $ttl, $homeurl, $background_color,$dashboard, $vconsole); break; case CUSTOM_GRAPH_BULLET_CHART: return stacked_bullet_chart($flash_charts, $graph_values, diff --git a/pandora_console/include/functions_visual_map.php b/pandora_console/include/functions_visual_map.php index 2ca3115b18..e384b78f1c 100755 --- a/pandora_console/include/functions_visual_map.php +++ b/pandora_console/include/functions_visual_map.php @@ -88,7 +88,7 @@ function visual_map_print_user_line_handles($layoutData) { } function visual_map_print_item($mode = "read", $layoutData, - $proportion = null, $show_links = true, $isExternalLink = false) { + $proportion = null, $show_links = true, $isExternalLink = false, $graph_javascript = true) { global $config; require_once ($config["homedir"] . '/include/functions_graph.php'); @@ -771,12 +771,15 @@ function visual_map_print_item($mode = "read", $layoutData, if ($layoutData['id_custom_graph'] != 0) { $img = custom_graphs_print( $layoutData['id_custom_graph'], $height, $width, - $period, null, true, 0, true, $layoutData['image']); + $period, null, true, 0, true, $layoutData['image'], + array(), '', array(), array(), true, + true, true, true, 1, false, $graph_javascript); } else { $img = grafico_modulo_sparse($id_module, $period, 0, $width, - $height, '', null, false, 1, false, 0, '', 0, 0, true, true, - '', 1, false, '', false, false, true, $layoutData['image']); + $height, '', null, false, 1, false, 0, '', 0, 0, + true, true, '', 1, false, '', false, false, true, + $layoutData['image'], null, false, $graph_javascript); } //Restore db connection @@ -1918,7 +1921,7 @@ function visual_map_print_user_lines($layout_data, $proportion = null) { * @param bool $draw_lines */ function visual_map_print_visual_map ($id_layout, $show_links = true, - $draw_lines = true, $width = null, $height = null, $home_url = '', $isExternalLink = false) { + $draw_lines = true, $width = null, $height = null, $home_url = '', $isExternalLink = false, $graph_javascript = true) { enterprise_include_once('include/functions_visual_map.php'); @@ -2067,7 +2070,7 @@ function visual_map_print_visual_map ($id_layout, $show_links = true, break; default: visual_map_print_item("read", $layout_data, - $proportion, $show_links, $isExternalLink); + $proportion, $show_links, $isExternalLink, $graph_javascript); break; } } diff --git a/pandora_console/include/graphs/fgraph.php b/pandora_console/include/graphs/fgraph.php index 10fcd81883..12b249d036 100644 --- a/pandora_console/include/graphs/fgraph.php +++ b/pandora_console/include/graphs/fgraph.php @@ -218,7 +218,7 @@ function area_graph($flash_chart, $chart_data, $width, $height, $color, $chart_extra_data = array(), $yellow_threshold = 0, $red_threshold = 0, $adapt_key = '', $force_integer = false, $series_suffix_str = '', $menu = true, $backgroundColor = 'white', - $dashboard = false) { + $dashboard = false, $vconsole = false) { setup_watermark($water_mark, $water_mark_file, $water_mark_url); @@ -260,35 +260,55 @@ function area_graph($flash_chart, $chart_data, $width, $height, $color, $dashboard); } else { - $graph = array(); - $graph['data'] = $chart_data; - $graph['width'] = $width; - $graph['height'] = $height; - $graph['color'] = $color; - $graph['legend'] = $legend; - $graph['xaxisname'] = $xaxisname; - $graph['yaxisname'] = $yaxisname; - $graph['water_mark'] = $water_mark_file; - $graph['font'] = $font; - $graph['font_size'] = $font_size; - $graph['backgroundColor'] = $backgroundColor; - $graph['unit'] = $unit; - $graph['series_type'] = $series_type; - - $id_graph = serialize_in_temp($graph, null, $ttl); - - // Warning: This string is used in the function "api_get_module_graph" from 'functions_api.php' with the regec patern "//" - - - - - return ""; + if ($vconsole) { + 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, + $force_integer, + $series_suffix_str, + $menu, + $backgroundColor, + $dashboard, + $vconsole); + } + else { + $graph = array(); + $graph['data'] = $chart_data; + $graph['width'] = $width; + $graph['height'] = $height; + $graph['color'] = $color; + $graph['legend'] = $legend; + $graph['xaxisname'] = $xaxisname; + $graph['yaxisname'] = $yaxisname; + $graph['water_mark'] = $water_mark_file; + $graph['font'] = $font; + $graph['font_size'] = $font_size; + $graph['backgroundColor'] = $backgroundColor; + $graph['unit'] = $unit; + $graph['series_type'] = $series_type; + + $id_graph = serialize_in_temp($graph, null, $ttl); + // Warning: This string is used in the function "api_get_module_graph" from 'functions_api.php' with the regec patern "//" + return ""; + } } } @@ -296,7 +316,7 @@ function stacked_area_graph($flash_chart, $chart_data, $width, $height, $color, $legend, $long_index, $no_data_image, $xaxisname = "", $yaxisname = "", $water_mark = "", $font = '', $font_size = '', $unit = '', $ttl = 1, $homeurl = '', $backgroundColor = 'white', - $dashboard = false) { + $dashboard = false, $vconsole = false) { setup_watermark($water_mark, $water_mark_file, $water_mark_url); @@ -327,25 +347,51 @@ function stacked_area_graph($flash_chart, $chart_data, $width, $height, $dashboard); } else { - //Stack the data - stack_data($chart_data, $legend, $color); - - $graph = array(); - $graph['data'] = $chart_data; - $graph['width'] = $width; - $graph['height'] = $height; - $graph['color'] = $color; - $graph['legend'] = $legend; - $graph['xaxisname'] = $xaxisname; - $graph['yaxisname'] = $yaxisname; - $graph['water_mark'] = $water_mark_file; - $graph['font'] = $font; - $graph['font_size'] = $font_size; - $graph['backgroundColor'] = $backgroundColor; - - $id_graph = serialize_in_temp($graph, null, $ttl); - - return ""; + if ($vconsole) { + return flot_area_stacked_graph( + $chart_data, + $width, + $height, + $color, + $legend, + $long_index, + $homeurl, + $unit, + $water_mark_url, + array(), + array(), + 0, + 0, + '', + false, + '', + true, + $backgroundColor, + $dashboard, + $vconsole); + } + else { + //Stack the data + stack_data($chart_data, $legend, $color); + + $graph = array(); + $graph['data'] = $chart_data; + $graph['width'] = $width; + $graph['height'] = $height; + $graph['color'] = $color; + $graph['legend'] = $legend; + $graph['xaxisname'] = $xaxisname; + $graph['yaxisname'] = $yaxisname; + $graph['water_mark'] = $water_mark_file; + $graph['font'] = $font; + $graph['font_size'] = $font_size; + $graph['backgroundColor'] = $backgroundColor; + + $id_graph = serialize_in_temp($graph, null, $ttl); + + return ""; + } } } @@ -353,7 +399,7 @@ function stacked_line_graph($flash_chart, $chart_data, $width, $height, $color, $legend, $long_index, $no_data_image, $xaxisname = "", $yaxisname = "", $water_mark = "", $font = '', $font_size = '', $unit = '', $ttl = 1, $homeurl = '', $backgroundColor = 'white', - $dashboard = false) { + $dashboard = false, $vconsole = false) { setup_watermark($water_mark, $water_mark_file, $water_mark_url); @@ -385,25 +431,50 @@ function stacked_line_graph($flash_chart, $chart_data, $width, $height, $dashboard); } else { - //Stack the data - stack_data($chart_data, $legend, $color); - - $graph = array(); - $graph['data'] = $chart_data; - $graph['width'] = $width; - $graph['height'] = $height; - $graph['color'] = $color; - $graph['legend'] = $legend; - $graph['xaxisname'] = $xaxisname; - $graph['yaxisname'] = $yaxisname; - $graph['water_mark'] = $water_mark_file; - $graph['font'] = $font; - $graph['font_size'] = $font_size; - $graph['backgroundColor'] = $backgroundColor; - - $id_graph = serialize_in_temp($graph, null, $ttl); - - return ""; + if ($vconsole) { + return flot_line_stacked_graph( + $chart_data, + $width, + $height, + $color, + $legend, + $long_index, + $homeurl, + $unit, + $water_mark_url, + array(), + array(), + 0, + 0, + '', + false, + '', + true, + $background_color, + $dashboard, + $vconsole); + } + else { + //Stack the data + stack_data($chart_data, $legend, $color); + + $graph = array(); + $graph['data'] = $chart_data; + $graph['width'] = $width; + $graph['height'] = $height; + $graph['color'] = $color; + $graph['legend'] = $legend; + $graph['xaxisname'] = $xaxisname; + $graph['yaxisname'] = $yaxisname; + $graph['water_mark'] = $water_mark_file; + $graph['font'] = $font; + $graph['font_size'] = $font_size; + $graph['backgroundColor'] = $backgroundColor; + + $id_graph = serialize_in_temp($graph, null, $ttl); + + return ""; + } } } @@ -464,7 +535,7 @@ function line_graph($flash_chart, $chart_data, $width, $height, $color, $legend, $long_index, $no_data_image, $xaxisname = "", $yaxisname = "", $water_mark = "", $font = '', $font_size = '', $unit = '', $ttl = 1, $homeurl = '', $backgroundColor = 'white', - $dashboard = false) { + $dashboard = false, $vconsole = false) { setup_watermark($water_mark, $water_mark_file, $water_mark_url); @@ -495,22 +566,47 @@ function line_graph($flash_chart, $chart_data, $width, $height, $color, $dashboard); } else { - $graph = array(); - $graph['data'] = $chart_data; - $graph['width'] = $width; - $graph['height'] = $height; - $graph['color'] = $color; - $graph['legend'] = $legend; - $graph['xaxisname'] = $xaxisname; - $graph['yaxisname'] = $yaxisname; - $graph['water_mark'] = $water_mark_file; - $graph['font'] = $font; - $graph['font_size'] = $font_size; - $graph['backgroundColor'] = $backgroundColor; - - $id_graph = serialize_in_temp($graph, null, $ttl); - - return ""; + if ($vconsole) { + return flot_line_simple_graph( + $chart_data, + $width, + $height, + $color, + $legend, + $long_index, + $homeurl, + $unit, + $water_mark_url, + array(), + array(), + 0, + 0, + '', + false, + '', + true, + $backgroundColor, + $dashboard, + $vconsole); + } + else { + $graph = array(); + $graph['data'] = $chart_data; + $graph['width'] = $width; + $graph['height'] = $height; + $graph['color'] = $color; + $graph['legend'] = $legend; + $graph['xaxisname'] = $xaxisname; + $graph['yaxisname'] = $yaxisname; + $graph['water_mark'] = $water_mark_file; + $graph['font'] = $font; + $graph['font_size'] = $font_size; + $graph['backgroundColor'] = $backgroundColor; + + $id_graph = serialize_in_temp($graph, null, $ttl); + + return ""; + } } } diff --git a/pandora_console/include/graphs/flot/pandora.flot.js b/pandora_console/include/graphs/flot/pandora.flot.js index c48ba0f143..45283b24a2 100644 --- a/pandora_console/include/graphs/flot/pandora.flot.js +++ b/pandora_console/include/graphs/flot/pandora.flot.js @@ -706,7 +706,7 @@ function pandoraFlotVBars(graph_id, values, labels, labels_long, legend, colors, } } -function pandoraFlotSlicebar(graph_id, values, datacolor, labels, legend, acumulate_data, intervaltick, water_mark, maxvalue, separator, separator2) { +function pandoraFlotSlicebar(graph_id, values, datacolor, labels, legend, acumulate_data, intervaltick, water_mark, maxvalue, separator, separator2, graph_javascript) { values = values.split(separator2); labels = labels.split(separator); @@ -804,7 +804,7 @@ 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) { + force_integer, separator, separator2, series_suffix_str, vconsole) { var threshold = true; var thresholded = false; @@ -1024,11 +1024,25 @@ function pandoraFlotArea(graph_id, values, labels, labels_long, legend, labelFormatter: lFormatter } }; - + if (vconsole) { + options.grid['hoverable'] = false; + options.grid['clickable'] = false; + options.crosshair = false; + options.selection = false; + } + var stack = 0, bars = true, lines = false, steps = false; var plot = $.plot($('#' + graph_id), datas, options); - + + if (vconsole) { + var myCanvas = plot.getCanvas(); + plot.setupGrid(); // redraw plot to new size + plot.draw(); + var image = myCanvas.toDataURL("image/png"); + return; + } + // Adjust the overview plot to the width and position of the main plot adjust_left_width_canvas(graph_id, 'overview_'+graph_id); @@ -1267,7 +1281,7 @@ function pandoraFlotArea(graph_id, values, labels, labels_long, legend, $('#'+graph_id).bind('mouseout',resetInteractivity); $('#overview_'+graph_id).bind('mouseout',resetInteractivity); - + // Reset interactivity styles function resetInteractivity() { $('#timestamp_'+graph_id).hide(); diff --git a/pandora_console/include/graphs/functions_d3.php b/pandora_console/include/graphs/functions_d3.php index a76d1f3c55..6e135c1492 100644 --- a/pandora_console/include/graphs/functions_d3.php +++ b/pandora_console/include/graphs/functions_d3.php @@ -152,7 +152,7 @@ function d3_bullet_chart($chart_data, $width, $height, $color, $legend, $id_bullet = uniqid(); $output .= - '
+ '