Merge branch 'ent-3630-7648-7712-campo-label-no-se-muestra-en-informes-de-graficas' into 'develop'

fixed label reports and more fixed

See merge request artica/pandorafms!2413
This commit is contained in:
Alejandro Fraguas 2019-05-24 10:47:15 +02:00
commit f5586d7b70
5 changed files with 935 additions and 591 deletions

View File

@ -4865,7 +4865,6 @@ function chooseType() {
switch (type) { switch (type) {
case 'event_report_agent': case 'event_report_agent':
case 'simple_graph': case 'simple_graph':
case 'agent_configuration':
case 'event_report_module': case 'event_report_module':
case 'alert_report_agent': case 'alert_report_agent':
case 'alert_report_module': case 'alert_report_module':
@ -4876,8 +4875,6 @@ function chooseType() {
case 'min_value': case 'min_value':
case 'max_value': case 'max_value':
case 'avg_value': case 'avg_value':
case 'projection_graph':
case 'prediction_date':
case 'TTRT': case 'TTRT':
case 'TTO': case 'TTO':
case 'MTBF': case 'MTBF':

File diff suppressed because it is too large Load Diff

View File

@ -1914,6 +1914,11 @@ function reporting_event_report_module(
$return['title'] = $content['name']; $return['title'] = $content['name'];
$return['subtitle'] = agents_get_alias($content['id_agent']).' - '.io_safe_output(modules_get_agentmodule_name($content['id_agent_module'])); $return['subtitle'] = agents_get_alias($content['id_agent']).' - '.io_safe_output(modules_get_agentmodule_name($content['id_agent_module']));
$return['label'] = (isset($content['style']['label'])) ? $content['style']['label'] : '';
if ($return['label'] != '') {
$return['label'] = reporting_label_macro($content, $return['label']);
}
if (is_metaconsole()) { if (is_metaconsole()) {
metaconsole_restore_db(); metaconsole_restore_db();
} }
@ -1921,7 +1926,6 @@ function reporting_event_report_module(
$return['description'] = $content['description']; $return['description'] = $content['description'];
$return['show_extended_events'] = $content['show_extended_events']; $return['show_extended_events'] = $content['show_extended_events'];
$return['date'] = reporting_get_date_text($report, $content); $return['date'] = reporting_get_date_text($report, $content);
$return['label'] = (isset($content['style']['label'])) ? $content['style']['label'] : '';
$event_filter = $content['style']; $event_filter = $content['style'];
$return['show_summary_group'] = $event_filter['show_summary_group']; $return['show_summary_group'] = $event_filter['show_summary_group'];
@ -2741,6 +2745,17 @@ function reporting_group_report($report, $content)
} }
/**
* Create data report event agent.
*
* @param array $report Data report.
* @param array $content Content report.
* @param string $type Type report.
* @param integer $force_width_chart Force width.
* @param integer $force_height_chart Force height.
*
* @return array Data.
*/
function reporting_event_report_agent( function reporting_event_report_agent(
$report, $report,
$content, $content,
@ -2761,26 +2776,26 @@ function reporting_event_report_agent(
$history = true; $history = true;
} }
$return['title'] = $content['name']; $return['title'] = $content['name'];
$return['subtitle'] = agents_get_alias($content['id_agent']); $return['subtitle'] = agents_get_alias($content['id_agent']);
$return['description'] = $content['description']; $return['description'] = $content['description'];
$return['date'] = reporting_get_date_text($report, $content); $return['date'] = reporting_get_date_text($report, $content);
$return['label'] = (isset($content['style']['label'])) ? $content['style']['label'] : '';
$return['show_summary_group'] = $content['style']['show_summary_group']; $return['show_summary_group'] = $content['style']['show_summary_group'];
$return['show_extended_events'] = $content['show_extended_events']; $return['show_extended_events'] = $content['show_extended_events'];
$style = $content['style']; $style = $content['style'];
// filter // Filter.
$show_summary_group = $style['show_summary_group']; $show_summary_group = $style['show_summary_group'];
$filter_event_severity = json_decode($style['filter_event_severity'], true); $filter_event_severity = json_decode($style['filter_event_severity'], true);
$filter_event_type = json_decode($style['filter_event_type'], true); $filter_event_type = json_decode($style['filter_event_type'], true);
$filter_event_status = json_decode($style['filter_event_status'], true); $filter_event_status = json_decode($style['filter_event_status'], true);
$filter_event_filter_search = $style['event_filter_search']; $filter_event_filter_search = $style['event_filter_search'];
// graph // Graph.
$event_graph_by_user_validator = $style['event_graph_by_user_validator']; $event_graph_by_user_validator = $style['event_graph_by_user_validator'];
$event_graph_by_criticity = $style['event_graph_by_criticity']; $event_graph_by_criticity = $style['event_graph_by_criticity'];
$event_graph_validated_vs_unvalidated = $style['event_graph_validated_vs_unvalidated']; $event_graph_validated_vs_unvalidated = $style['event_graph_validated_vs_unvalidated'];
$return['data'] = reporting_get_agents_detailed_event( $return['data'] = reporting_get_agents_detailed_event(
@ -2825,6 +2840,12 @@ function reporting_event_report_agent(
$metaconsole_dbtable = false; $metaconsole_dbtable = false;
} }
$label = (isset($content['style']['label'])) ? $content['style']['label'] : '';
if ($label != '') {
$label = reporting_label_macro($content, $label);
}
$return['label'] = $label;
if ($event_graph_by_user_validator) { if ($event_graph_by_user_validator) {
$data_graph = events_get_count_events_validated_by_user( $data_graph = events_get_count_events_validated_by_user(
['id_agent' => $content['id_agent']], ['id_agent' => $content['id_agent']],
@ -2908,7 +2929,7 @@ function reporting_event_report_agent(
metaconsole_restore_db(); metaconsole_restore_db();
} }
// total_events // Total events.
if ($return['data'] != '') { if ($return['data'] != '') {
$return['total_events'] = count($return['data']); $return['total_events'] = count($return['data']);
} else { } else {
@ -2941,7 +2962,11 @@ function reporting_historical_data($report, $content)
$return['subtitle'] = $agent_name.' - '.$module_name; $return['subtitle'] = $agent_name.' - '.$module_name;
$return['description'] = $content['description']; $return['description'] = $content['description'];
$return['date'] = reporting_get_date_text($report, $content); $return['date'] = reporting_get_date_text($report, $content);
$return['label'] = (isset($content['style']['label'])) ? $content['style']['label'] : ''; $return['label'] = (isset($content['style']['label'])) ? $content['style']['label'] : '';
if ($return['label'] != '') {
$return['label'] = reporting_label_macro($content, $return['label']);
}
$return['keys'] = [ $return['keys'] = [
__('Date'), __('Date'),
@ -3017,7 +3042,6 @@ function reporting_database_serialized($report, $content)
$return['subtitle'] = $agent_name.' - '.$module_name; $return['subtitle'] = $agent_name.' - '.$module_name;
$return['description'] = $content['description']; $return['description'] = $content['description'];
$return['date'] = reporting_get_date_text($report, $content); $return['date'] = reporting_get_date_text($report, $content);
$return['label'] = (isset($content['style']['label'])) ? $content['style']['label'] : '';
$keys = []; $keys = [];
if (isset($content['header_definition']) && ($content['header_definition'] != '')) { if (isset($content['header_definition']) && ($content['header_definition'] != '')) {
@ -3043,6 +3067,11 @@ function reporting_database_serialized($report, $content)
metaconsole_connect($server); metaconsole_connect($server);
} }
$return['label'] = (isset($content['style']['label'])) ? $content['style']['label'] : '';
if ($return['label'] != '') {
$return['label'] = reporting_label_macro($content, $return['label']);
}
$datelimit = ($report['datetime'] - $content['period']); $datelimit = ($report['datetime'] - $content['period']);
$search_in_history_db = db_search_in_history_db($datelimit); $search_in_history_db = db_search_in_history_db($datelimit);
@ -3589,7 +3618,12 @@ function reporting_alert_report_agent($report, $content)
$return['subtitle'] = $agent_name; $return['subtitle'] = $agent_name;
$return['description'] = $content['description']; $return['description'] = $content['description'];
$return['date'] = reporting_get_date_text($report, $content); $return['date'] = reporting_get_date_text($report, $content);
$return['label'] = (isset($content['style']['label'])) ? $content['style']['label'] : ''; $return['label'] = (isset($content['style']['label'])) ? $content['style']['label'] : '';
if ($return['label'] != '') {
$return['label'] = reporting_label_macro($content, $return['label']);
}
$module_list = agents_get_modules($content['id_agent']); $module_list = agents_get_modules($content['id_agent']);
$data = []; $data = [];
@ -3721,6 +3755,9 @@ function reporting_alert_report_module($report, $content)
$return['description'] = $content['description']; $return['description'] = $content['description'];
$return['date'] = reporting_get_date_text($report, $content); $return['date'] = reporting_get_date_text($report, $content);
$return['label'] = (isset($content['style']['label'])) ? $content['style']['label'] : ''; $return['label'] = (isset($content['style']['label'])) ? $content['style']['label'] : '';
if ($return['label'] != '') {
$return['label'] = reporting_label_macro($content, $return['label']);
}
$data_row = []; $data_row = [];
@ -3923,7 +3960,6 @@ function reporting_monitor_report($report, $content)
$return['subtitle'] = $agent_name.' - '.$module_name; $return['subtitle'] = $agent_name.' - '.$module_name;
$return['description'] = $content['description']; $return['description'] = $content['description'];
$return['date'] = reporting_get_date_text($report, $content); $return['date'] = reporting_get_date_text($report, $content);
$return['label'] = (isset($content['style']['label'])) ? $content['style']['label'] : '';
if ($config['metaconsole']) { if ($config['metaconsole']) {
$id_meta = metaconsole_get_id_server($content['server_name']); $id_meta = metaconsole_get_id_server($content['server_name']);
@ -3932,6 +3968,11 @@ function reporting_monitor_report($report, $content)
metaconsole_connect($server); metaconsole_connect($server);
} }
$return['label'] = (isset($content['style']['label'])) ? $content['style']['label'] : '';
if ($return['label'] != '') {
$return['label'] = reporting_label_macro($content, $return['label']);
}
$module_name = io_safe_output( $module_name = io_safe_output(
modules_get_agentmodule_name($content['id_agent_module']) modules_get_agentmodule_name($content['id_agent_module'])
); );
@ -7335,6 +7376,7 @@ function reporting_simple_graph(
$report, $report,
$content $content
); );
$label = (isset($content['style']['label'])) ? $content['style']['label'] : ''; $label = (isset($content['style']['label'])) ? $content['style']['label'] : '';
if ($label != '') { if ($label != '') {
$label = reporting_label_macro($content, $label); $label = reporting_label_macro($content, $label);
@ -7346,7 +7388,7 @@ function reporting_simple_graph(
$return['chart'] = ''; $return['chart'] = '';
// Get chart // Get chart.
reporting_set_conf_charts($width, $height, $only_image, $type, $content, $ttl); reporting_set_conf_charts($width, $height, $only_image, $type, $content, $ttl);
if (!empty($force_width_chart)) { if (!empty($force_width_chart)) {

View File

@ -1,3 +1,5 @@
/* global $ */
function pandoraFlotPie( function pandoraFlotPie(
graph_id, graph_id,
values, values,
@ -1074,7 +1076,6 @@ function pandoraFlotArea(
.split(".") .split(".")
.shift(); .shift();
var width = params.width; var width = params.width;
var height = params.height;
var vconsole = params.vconsole; var vconsole = params.vconsole;
var dashboard = params.dashboard; var dashboard = params.dashboard;
var menu = params.menu; var menu = params.menu;
@ -1088,9 +1089,8 @@ function pandoraFlotArea(
var background_color = params.backgroundColor; var background_color = params.backgroundColor;
var legend_color = params.legend_color; var legend_color = params.legend_color;
var update_legend = {}; var update_legend = {};
//XXXXXX colocar
var force_integer = 0; var force_integer = 0;
var title = params.title;
if (typeof type === "undefined" || type == "") { if (typeof type === "undefined" || type == "") {
type = params.type_graph; type = params.type_graph;
@ -1105,8 +1105,6 @@ function pandoraFlotArea(
var red_up = parseFloat(data_module_graph.c_max); var red_up = parseFloat(data_module_graph.c_max);
var yellow_inverse = parseInt(data_module_graph.w_inv); var yellow_inverse = parseInt(data_module_graph.w_inv);
var red_inverse = parseInt(data_module_graph.c_inv); var red_inverse = parseInt(data_module_graph.c_inv);
//XXXXX
var markins_graph = true; var markins_graph = true;
// If threshold and up are the same, that critical or warning is disabled // If threshold and up are the same, that critical or warning is disabled
@ -1934,11 +1932,12 @@ function pandoraFlotArea(
} }
} }
var stacked = null;
var filled_s = 0.3;
switch (type) { switch (type) {
case "line": case "line":
case 2: case 2:
stacked = null;
filled_s = false;
break; break;
case 3: case 3:
stacked = "stack"; stacked = "stack";
@ -1960,7 +1959,15 @@ function pandoraFlotArea(
var data_base = new Array(); var data_base = new Array();
var lineWidth = $("#hidden-line_width_graph").val() || 1; var lineWidth = $("#hidden-line_width_graph").val() || 1;
i = 0; var i = 0;
var fill_color = "green";
var line_show = true;
var points_show = false;
var filled = false;
var steps_chart = false;
var radius = false;
var fill_points = fill_color;
$.each(values, function(index, value) { $.each(values, function(index, value) {
if (typeof value.data !== "undefined") { if (typeof value.data !== "undefined") {
if (index.search("alert") >= 0) { if (index.search("alert") >= 0) {
@ -1974,7 +1981,7 @@ function pandoraFlotArea(
switch (series_type[index]) { switch (series_type[index]) {
case "area": case "area":
line_show = true; line_show = true;
points_show = false; // XXX - false points_show = false;
filled = filled_s; filled = filled_s;
steps_chart = false; steps_chart = false;
radius = false; radius = false;
@ -1995,7 +2002,7 @@ function pandoraFlotArea(
points_show = true; points_show = true;
filled = false; filled = false;
steps_chart = false; steps_chart = false;
radius = 1.5; radius = 3;
fill_points = fill_color; fill_points = fill_color;
break; break;
case "unknown": case "unknown":
@ -2033,7 +2040,7 @@ function pandoraFlotArea(
}, },
points: { points: {
show: points_show, show: points_show,
radius: 3, radius: radius,
fillColor: fill_points fillColor: fill_points
}, },
legend: legend.index legend: legend.index
@ -2051,7 +2058,8 @@ function pandoraFlotArea(
number_ticks = 5; number_ticks = 5;
} }
var maxticks = date_array["period"] / 3600 / number_ticks; // masticks this variable is commented because the library defines the tick number by itself
// var maxticks = date_array["period"] / 3600 / number_ticks;
var options = { var options = {
series: { series: {
@ -2125,16 +2133,11 @@ function pandoraFlotArea(
options.selection = false; options.selection = false;
} }
var stack = 0,
bars = true,
lines = false,
steps = false;
var plot = $.plot($("#" + graph_id), datas, options); var plot = $.plot($("#" + graph_id), datas, options);
// Re-calculate the graph height with the legend height // Re-calculate the graph height with the legend height
if (dashboard) { if (dashboard) {
$acum = 0; var $acum = 0;
if (dashboard) $acum = 35; if (dashboard) $acum = 35;
var hDiff = var hDiff =
$("#" + graph_id).height() - $("#legend_" + graph_id).height() - $acum; $("#" + graph_id).height() - $("#legend_" + graph_id).height() - $acum;
@ -2143,22 +2146,12 @@ function pandoraFlotArea(
navigator.userAgent navigator.userAgent
) )
) { ) {
// not defined.???
} else { } else {
$("#" + graph_id).css("height", hDiff); $("#" + graph_id).css("height", hDiff);
} }
} }
/*
//XXXREvisar esto
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 the overview plot to the width and position of the main plot
adjust_left_width_canvas(graph_id, "overview_" + graph_id); adjust_left_width_canvas(graph_id, "overview_" + graph_id);
update_left_width_canvas(graph_id); update_left_width_canvas(graph_id);
@ -2251,7 +2244,7 @@ function pandoraFlotArea(
return; return;
} }
dataInSelection = ranges.xaxis.to - ranges.xaxis.from; var dataInSelection = ranges.xaxis.to - ranges.xaxis.from;
var maxticks_zoom = dataInSelection / 3600000 / number_ticks; var maxticks_zoom = dataInSelection / 3600000 / number_ticks;
if (maxticks_zoom < 0.001) { if (maxticks_zoom < 0.001) {
@ -2261,8 +2254,9 @@ function pandoraFlotArea(
} }
} }
var y_recal = "";
if (thresholded) { if (thresholded) {
var y_recal = axis_thresholded( y_recal = axis_thresholded(
threshold_data, threshold_data,
plot.getAxes().yaxis.min, plot.getAxes().yaxis.min,
plot.getAxes().yaxis.max, plot.getAxes().yaxis.max,
@ -2271,11 +2265,11 @@ function pandoraFlotArea(
red_up red_up
); );
} else { } else {
var y_recal = ranges.yaxis; y_recal = ranges.yaxis;
} }
if (thresholded) { if (thresholded) {
data_base_treshold = add_threshold( var data_base_treshold = add_threshold(
data_base, data_base,
threshold_data, threshold_data,
ranges.yaxis.from, ranges.yaxis.from,
@ -2400,7 +2394,6 @@ function pandoraFlotArea(
var updateLegendTimeout = null; var updateLegendTimeout = null;
var latestPosition = null; var latestPosition = null;
var currentPlot = null; var currentPlot = null;
var currentRanges = null;
// Update legend with the data of the plot in the mouse position // Update legend with the data of the plot in the mouse position
function updateLegend() { function updateLegend() {
@ -2434,7 +2427,7 @@ function pandoraFlotArea(
"Dec" "Dec"
]; ];
date_format = var date_format =
(d.getDate() < 10 ? "0" : "") + (d.getDate() < 10 ? "0" : "") +
d.getDate() + d.getDate() +
" " + " " +
@ -2455,7 +2448,7 @@ function pandoraFlotArea(
var timesize = $("#timestamp_" + graph_id).width(); var timesize = $("#timestamp_" + graph_id).width();
dataset = currentPlot.getData(); var dataset = currentPlot.getData();
var timenewpos = var timenewpos =
dataset[0].xaxis.p2c(pos.x) + dataset[0].xaxis.p2c(pos.x) +
@ -2481,9 +2474,8 @@ function pandoraFlotArea(
$("#timestamp_" + graph_id).css("left", timenewpos); $("#timestamp_" + graph_id).css("left", timenewpos);
} }
var dataset = currentPlot.getData();
var i = 0; var i = 0;
for (k = 0; k < dataset.length; k++) { for (var k = 0; k < dataset.length; k++) {
// k is the real series counter // k is the real series counter
// i is the series counter without thresholds // i is the series counter without thresholds
var series = dataset[k]; var series = dataset[k];
@ -2492,7 +2484,7 @@ function pandoraFlotArea(
} }
// find the nearest points, x-wise // find the nearest points, x-wise
for (j = 0; j < series.data.length; ++j) { for (var j = 0; j < series.data.length; ++j) {
if (series.data[j][0] > pos.x) { if (series.data[j][0] > pos.x) {
break; break;
} }
@ -2503,10 +2495,10 @@ function pandoraFlotArea(
} }
} }
y_array = format_unit_yaxes(y); var y_array = format_unit_yaxes(y);
y = y_array["y"]; y = y_array["y"];
how_bigger = y_array["unit"]; var how_bigger = y_array["unit"];
var data_legend = []; var data_legend = [];
@ -2516,8 +2508,9 @@ function pandoraFlotArea(
series_type[dataset[k]["label"]] != "unknown" && series_type[dataset[k]["label"]] != "unknown" &&
series_type[dataset[k]["label"]] != "percentil" series_type[dataset[k]["label"]] != "percentil"
) { ) {
var label_aux = "";
if (Object.keys(update_legend).length == 0) { if (Object.keys(update_legend).length == 0) {
var label_aux = legend[series.label]; label_aux = legend[series.label];
$("#legend_" + graph_id + " .legendLabel") $("#legend_" + graph_id + " .legendLabel")
.eq(i) .eq(i)
@ -2532,6 +2525,16 @@ function pandoraFlotArea(
unit unit
); );
} else { } else {
var min_y_array;
var min_y = 0;
var min_bigger = "";
var max_y_array;
var max_y = 0;
var max_bigger = "";
var avg_y_array;
var avg_y = 0;
var avg_bigger = "";
$.each(update_legend, function(index, value) { $.each(update_legend, function(index, value) {
if (!value[x]) { if (!value[x]) {
x = x + 1; x = x + 1;
@ -2581,7 +2584,7 @@ function pandoraFlotArea(
avg_bigger; avg_bigger;
}); });
var label_aux = label_aux =
legend[series.label].split(":")[0] + data_legend[series.label]; legend[series.label].split(":")[0] + data_legend[series.label];
$("#legend_" + graph_id + " .legendLabel") $("#legend_" + graph_id + " .legendLabel")
.eq(i) .eq(i)
@ -2604,7 +2607,7 @@ function pandoraFlotArea(
} }
// Events // Events
$("#overview_" + graph_id).bind("plothover", function(event, pos, item) { $("#overview_" + graph_id).bind("plothover", function(event, pos) {
plot.setCrosshair({ x: pos.x, y: pos.y }); plot.setCrosshair({ x: pos.x, y: pos.y });
currentPlot = plot; currentPlot = plot;
latestPosition = pos; latestPosition = pos;
@ -2613,7 +2616,7 @@ function pandoraFlotArea(
} }
}); });
$("#" + graph_id).bind("plothover", function(event, pos, item) { $("#" + graph_id).bind("plothover", function(event, pos) {
overview.setCrosshair({ x: pos.x, y: pos.y }); overview.setCrosshair({ x: pos.x, y: pos.y });
currentPlot = plot; currentPlot = plot;
latestPosition = pos; latestPosition = pos;
@ -2636,7 +2639,6 @@ function pandoraFlotArea(
$("#extra_" + graph_id).css("width", "170px"); $("#extra_" + graph_id).css("width", "170px");
$("#extra_" + graph_id).css("height", "60px"); $("#extra_" + graph_id).css("height", "60px");
var dataset = plot.getData();
var extra_info = "<i>No info to show</i>"; var extra_info = "<i>No info to show</i>";
var extra_show = false; var extra_show = false;
var extra_height = $("#extra_" + graph_id).height(); var extra_height = $("#extra_" + graph_id).height();
@ -2657,8 +2659,6 @@ function pandoraFlotArea(
coord_x = coord_x - extra_width; coord_x = coord_x - extra_width;
} }
var coord_y = offset_graph.top + height_legend + extra_height;
$("#extra_" + graph_id).css("left", coord_x); $("#extra_" + graph_id).css("left", coord_x);
$("#extra_" + graph_id).css("top", coord_y); $("#extra_" + graph_id).css("top", coord_y);
@ -2677,21 +2677,22 @@ function pandoraFlotArea(
}); });
}); });
var extra_color = "#ffffff";
if (events_data.event_type.search("alert") >= 0) { if (events_data.event_type.search("alert") >= 0) {
$extra_color = "#FFA631"; extra_color = "#FFA631";
} else if (events_data.event_type.search("critical") >= 0) { } else if (events_data.event_type.search("critical") >= 0) {
$extra_color = "#FC4444"; extra_color = "#FC4444";
} else if (events_data.event_type.search("warning") >= 0) { } else if (events_data.event_type.search("warning") >= 0) {
$extra_color = "#FAD403"; extra_color = "#FAD403";
} else if (events_data.event_type.search("unknown") >= 0) { } else if (events_data.event_type.search("unknown") >= 0) {
$extra_color = "#3BA0FF"; extra_color = "#3BA0FF";
} else if (events_data.event_type.search("normal") >= 0) { } else if (events_data.event_type.search("normal") >= 0) {
$extra_color = "#80BA27"; extra_color = "#80BA27";
} else { } else {
$extra_color = "#ffffff"; extra_color = "#ffffff";
} }
$("#extra_" + graph_id).css("background-color", $extra_color); $("#extra_" + graph_id).css("background-color", extra_color);
extra_info = "<b>" + events_data.evento + ":"; extra_info = "<b>" + events_data.evento + ":";
extra_info += extra_info +=
@ -2717,9 +2718,10 @@ function pandoraFlotArea(
} }
if (image_treshold) { if (image_treshold) {
var y_recal = plot.getAxes().yaxis.max;
if (!thresholded) { if (!thresholded) {
// Recalculate the y axis // Recalculate the y axis
var y_recal = axis_thresholded( y_recal = axis_thresholded(
threshold_data, threshold_data,
plot.getAxes().yaxis.min, plot.getAxes().yaxis.min,
plot.getAxes().yaxis.max, plot.getAxes().yaxis.max,
@ -2727,11 +2729,9 @@ function pandoraFlotArea(
extremes, extremes,
red_up red_up
); );
} else {
var y_recal = plot.getAxes().yaxis.max;
} }
datas_treshold = add_threshold( var datas_treshold = add_threshold(
data_base, data_base,
threshold_data, threshold_data,
plot.getAxes().yaxis.min, plot.getAxes().yaxis.min,
@ -2762,7 +2762,7 @@ function pandoraFlotArea(
// Reset interactivity styles // Reset interactivity styles
function resetInteractivity() { function resetInteractivity() {
$("#timestamp_" + graph_id).hide(); $("#timestamp_" + graph_id).hide();
dataset = plot.getData(); var dataset = plot.getData();
for (i = 0; i < dataset.length; ++i) { for (i = 0; i < dataset.length; ++i) {
var series = dataset[i]; var series = dataset[i];
var label_aux = legend[series.label]; var label_aux = legend[series.label];
@ -2784,15 +2784,14 @@ function pandoraFlotArea(
overview.clearCrosshair(); overview.clearCrosshair();
} }
function yFormatter(v, axis) { function yFormatter(v) {
var formatted = v;
if (short_data) { if (short_data) {
var formatted = number_format(v, force_integer, "", short_data); formatted = number_format(v, force_integer, "", short_data);
} else { } else {
// It is an integer // It is an integer
if (v - Math.floor(v) == 0) { if (v - Math.floor(v) == 0) {
var formatted = number_format(v, force_integer, "", 2); formatted = number_format(v, force_integer, "", 2);
} else {
var formatted = v;
} }
} }
@ -2801,7 +2800,7 @@ function pandoraFlotArea(
return formatted; return formatted;
} }
function lFormatter(v, item) { function lFormatter(v) {
return '<span style="color:' + legend_color + '">' + legend[v] + "</span>"; return '<span style="color:' + legend_color + '">' + legend[v] + "</span>";
} }
@ -2858,9 +2857,10 @@ function pandoraFlotArea(
); );
thresholded = false; thresholded = false;
} else { } else {
var y_recal = plot.getAxes().yaxis.max;
if (!thresholded) { if (!thresholded) {
// Recalculate the y axis // Recalculate the y axis
var y_recal = axis_thresholded( y_recal = axis_thresholded(
threshold_data, threshold_data,
plot.getAxes().yaxis.min, plot.getAxes().yaxis.min,
plot.getAxes().yaxis.max, plot.getAxes().yaxis.max,
@ -2868,8 +2868,6 @@ function pandoraFlotArea(
extremes, extremes,
red_up red_up
); );
} else {
var y_recal = plot.getAxes().yaxis.max;
} }
datas_treshold = add_threshold( datas_treshold = add_threshold(
@ -2917,7 +2915,6 @@ function pandoraFlotArea(
homeurl + "images/zoom_cross.disabled.png" homeurl + "images/zoom_cross.disabled.png"
); );
overview.clearSelection(); overview.clearSelection();
currentRanges = null;
thresholded = false; thresholded = false;
max_draw = []; max_draw = [];
}); });
@ -2932,7 +2929,6 @@ function pandoraFlotArea(
// Add bottom margin in the legend // Add bottom margin in the legend
// Estimated height of 24 (works fine with this data in all browsers) // Estimated height of 24 (works fine with this data in all browsers)
menu_height = 24;
$("#legend_" + graph_id).css("margin-bottom", "10px"); $("#legend_" + graph_id).css("margin-bottom", "10px");
parent_height = parseInt( parent_height = parseInt(
$("#menu_" + graph_id) $("#menu_" + graph_id)
@ -2979,6 +2975,7 @@ function format_unit_yaxes(y) {
} }
function adjust_menu(graph_id, plot, parent_height, width, show_legend) { function adjust_menu(graph_id, plot, parent_height, width, show_legend) {
var left_ticks_width = 0;
if ( if (
$("#" + graph_id + " .xAxis .tickLabel") $("#" + graph_id + " .xAxis .tickLabel")
.eq(0) .eq(0)
@ -2988,14 +2985,11 @@ function adjust_menu(graph_id, plot, parent_height, width, show_legend) {
.eq(0) .eq(0)
.css("width") .css("width")
.split("px")[0]; .split("px")[0];
} else {
left_ticks_width = 0;
} }
var parent_height_new = 0; var legend_height = 0;
if (show_legend) { if (show_legend) {
var legend_height = legend_height =
parseInt( parseInt(
$("#legend_" + graph_id) $("#legend_" + graph_id)
.css("height") .css("height")
@ -3006,12 +3000,9 @@ function adjust_menu(graph_id, plot, parent_height, width, show_legend) {
.css("margin-top") .css("margin-top")
.split("px")[0] .split("px")[0]
); );
} else {
var legend_height = 0;
} }
var menu_height = "25"; var menu_height = "25";
if ( if (
$("#menu_" + graph_id).height() != undefined && $("#menu_" + graph_id).height() != undefined &&
$("#menu_" + graph_id).height() > 20 $("#menu_" + graph_id).height() > 20
@ -3019,7 +3010,7 @@ function adjust_menu(graph_id, plot, parent_height, width, show_legend) {
menu_height = $("#menu_" + graph_id).height(); menu_height = $("#menu_" + graph_id).height();
} }
offset = $("#" + graph_id)[0].offsetTop; var offset = $("#" + graph_id)[0].offsetTop;
$("#menu_" + graph_id).css("top", offset + "px"); $("#menu_" + graph_id).css("top", offset + "px");

View File

@ -82,9 +82,22 @@ function include_javascript_dependencies_flot_graph($return=false)
} }
// /**
// AREA GRAPHS //////// * Function create container for print charts.
// *
* @param integer $agent_module_id Id module.
* @param array $array_data Data.
* @param array $legend Legend.
* @param array $series_type Series.
* @param array $color Color.
* @param array $date_array Date.
* @param array $data_module_graph Data module.
* @param array $params Params.
* @param string $water_mark Water.
* @param array $array_events_alerts Events array.
*
* @return string Return graphs.
*/
function flot_area_graph( function flot_area_graph(
$agent_module_id, $agent_module_id,
$array_data, $array_data,
@ -99,8 +112,7 @@ function flot_area_graph(
) { ) {
global $config; global $config;
// include_javascript_dependencies_flot_graph(); // Get a unique identifier to graph.
// Get a unique identifier to graph
$graph_id = uniqid('graph_'); $graph_id = uniqid('graph_');
$background_style = ''; $background_style = '';
@ -126,19 +138,26 @@ function flot_area_graph(
break; break;
} }
$padding_vconsole = $params['dashboard'] ? 'padding: 1px 0px 10px 10px;' : ''; $padding_vconsole = ($params['dashboard']) ? 'padding: 1px 0px 10px 10px;' : '';
// Parent layer // Parent layer.
$return = "<div class='parent_graph' style='width: ".($params['width']).';'.$background_style.$padding_vconsole."'>"; $return = "<div class='parent_graph' style='width: ".($params['width']).';'.$background_style.$padding_vconsole."'>";
if (empty($params['title']) === false) {
$return .= '<p style="text-align:center;">'.$params['title'].'</p>';
}
// Set some containers to legend, graph, timestamp tooltip, etc. // Set some containers to legend, graph, timestamp tooltip, etc.
if ($params['show_legend']) { if ($params['show_legend']) {
$return .= "<p id='legend_$graph_id' style='text-align:left;'></p>"; $return .= '<p id="legend_'.$graph_id.'" style="text-align:left;"></p>';
} }
if (isset($params['graph_combined']) && $params['graph_combined'] if (isset($params['graph_combined']) && $params['graph_combined']
&& (!isset($params['from_interface']) || !$params['from_interface']) && (!isset($params['from_interface']) || !$params['from_interface'])
) { ) {
if (isset($params['threshold_data']) && is_array($params['threshold_data'])) { if (isset($params['threshold_data'])
&& is_array($params['threshold_data'])
) {
$yellow_threshold = $params['threshold_data']['yellow_threshold']; $yellow_threshold = $params['threshold_data']['yellow_threshold'];
$red_threshold = $params['threshold_data']['red_threshold']; $red_threshold = $params['threshold_data']['red_threshold'];
$yellow_up = $params['threshold_data']['yellow_up']; $yellow_up = $params['threshold_data']['yellow_up'];
@ -154,7 +173,7 @@ function flot_area_graph(
} else if (!isset($params['combined']) || !$params['combined']) { } else if (!isset($params['combined']) || !$params['combined']) {
$yellow_threshold = $data_module_graph['w_min']; $yellow_threshold = $data_module_graph['w_min'];
$red_threshold = $data_module_graph['c_min']; $red_threshold = $data_module_graph['c_min'];
// Get other required module datas to draw warning and critical // Get other required module datas to draw warning and critical.
if ($agent_module_id == 0) { if ($agent_module_id == 0) {
$yellow_up = 0; $yellow_up = 0;
$red_up = 0; $red_up = 0;
@ -166,8 +185,12 @@ function flot_area_graph(
$yellow_inverse = !($data_module_graph['w_inv'] == 0); $yellow_inverse = !($data_module_graph['w_inv'] == 0);
$red_inverse = !($data_module_graph['c_inv'] == 0); $red_inverse = !($data_module_graph['c_inv'] == 0);
} }
} else if (isset($params['from_interface']) && $params['from_interface']) { } else if (isset($params['from_interface'])
if (isset($params['threshold_data']) && is_array($params['threshold_data'])) { && $params['from_interface']
) {
if (isset($params['threshold_data'])
&& is_array($params['threshold_data'])
) {
$yellow_threshold = $params['threshold_data']['yellow_threshold']; $yellow_threshold = $params['threshold_data']['yellow_threshold'];
$red_threshold = $params['threshold_data']['red_threshold']; $red_threshold = $params['threshold_data']['red_threshold'];
$yellow_up = $params['threshold_data']['yellow_up']; $yellow_up = $params['threshold_data']['yellow_up'];
@ -200,7 +223,11 @@ function flot_area_graph(
); );
} }
$return .= html_print_input_hidden('line_width_graph', $config['custom_graph_width'], true); $return .= html_print_input_hidden(
'line_width_graph',
$config['custom_graph_width'],
true
);
$return .= "<div id='timestamp_$graph_id' $return .= "<div id='timestamp_$graph_id'
class='timestamp_graph' class='timestamp_graph'
style=' font-size:".$params['font_size']."pt; style=' font-size:".$params['font_size']."pt;
@ -239,20 +266,21 @@ function flot_area_graph(
$series_type_unique['data_'.$graph_id.'_'.$k] = $v; $series_type_unique['data_'.$graph_id.'_'.$k] = $v;
} }
// Store data series in javascript format // Store data series in javascript format.
$extra_width = (int) ($params['width'] / 3); $extra_width = (int) ($params['width'] / 3);
$return .= "<div id='extra_$graph_id' $return .= "<div id='extra_$graph_id'
style='font-size: ".$params['font_size'].'pt; style='font-size: ".$params['font_size'].'pt;
display:none; position:absolute; overflow: auto; display:none; position:absolute; overflow: auto;
max-height: '.($params['height'] + 50).'px; max-height: '.($params['height'] + 50).'px;
width: '.$extra_width."px; width: '.$extra_width."px;
background:#fff; padding: 2px 2px 2px 2px; background:#fff; padding: 2px 2px 2px 2px;
border: solid #000 1px;'></div>"; border: solid #000 1px;'></div>";
// Trick to get translated string from javascript // Trick to get translated string from javascript.
$return .= html_print_input_hidden('unknown_text', __('Unknown'), true); $return .= html_print_input_hidden('unknown_text', __('Unknown'), true);
$values = json_encode($array_data); $values = json_encode($array_data);
$legend = json_encode($legend); $legend = json_encode($legend);
$series_type = json_encode($series_type); $series_type = json_encode($series_type);
$color = json_encode($color); $color = json_encode($color);
@ -261,7 +289,7 @@ function flot_area_graph(
$params = json_encode($params); $params = json_encode($params);
$array_events_alerts = json_encode($array_events_alerts); $array_events_alerts = json_encode($array_events_alerts);
// Javascript code // Javascript code.
if ($font_size == '') { if ($font_size == '') {
$font_size = '\'\''; $font_size = '\'\'';
} }
@ -272,7 +300,7 @@ function flot_area_graph(
$return .= '});'; $return .= '});';
$return .= '</script>'; $return .= '</script>';
// Parent layer // Parent layer.
$return .= '</div>'; $return .= '</div>';
return $return; return $return;