fixed errors in graph min and max warning and critical for edition module

This commit is contained in:
daniel 2018-07-17 11:26:25 +02:00
parent 001861b746
commit f317f3e736
3 changed files with 87 additions and 89 deletions

View File

@ -303,7 +303,7 @@ if (modules_is_string_type($id_module_type) || $edit) {
$table_simple->data[4][1] .= html_print_checkbox ("warning_inverse", 1, $warning_inverse, true, $disabledBecauseInPolicy); $table_simple->data[4][1] .= html_print_checkbox ("warning_inverse", 1, $warning_inverse, true, $disabledBecauseInPolicy);
if (!modules_is_string_type($id_module_type) || $edit) { if (!modules_is_string_type($id_module_type) || $edit) {
$table_simple->data[4][2] = '<svg id="svg_dinamic" width="800" height="300"> </svg>'; $table_simple->data[4][2] = '<svg id="svg_dinamic" width="500" height="300"> </svg>';
} }
$table_simple->data[5][0] = __('Critical status').' ' . ui_print_help_icon ('critical_status', true); $table_simple->data[5][0] = __('Critical status').' ' . ui_print_help_icon ('critical_status', true);

View File

@ -129,7 +129,7 @@ $table->data[4][1] .= html_print_input_text ('str_warning', $str_warning,
$table->data[4][1] .= '<br /><em>'.__('Inverse interval').'</em>'; $table->data[4][1] .= '<br /><em>'.__('Inverse interval').'</em>';
$table->data[4][1] .= html_print_checkbox ("warning_inverse", 1, $warning_inverse, true); $table->data[4][1] .= html_print_checkbox ("warning_inverse", 1, $warning_inverse, true);
$table->data[4][2] = '<svg id="svg_dinamic" width="800" height="300"> </svg>'; $table->data[4][2] = '<svg id="svg_dinamic" width="500" height="300"> </svg>';
$table->colspan[4][2] = 2; $table->colspan[4][2] = 2;
$table->rowspan[4][2] = 3; $table->rowspan[4][2] = 3;

View File

@ -1264,13 +1264,14 @@ function pagination_show_more(params, message){
datatype: "html" datatype: "html"
}); });
} }
/* /*
*function use d3.js for paint graph *function use d3.js for paint graph
*/ */
function paint_graph_status(min_w, max_w, min_c, max_c, inverse_w, inverse_c, error_w, error_c, function paint_graph_status(min_w, max_w, min_c, max_c, inverse_w, inverse_c, error_w, error_c,
legend_normal, legend_warning, legend_critical, legend_normal, legend_warning, legend_critical,
message_error_warning, message_error_critical) { message_error_warning, message_error_critical) {
//Check if they are numbers //Check if they are numbers
if(isNaN(min_w)){ min_w = 0; }; if(isNaN(min_w)){ min_w = 0; };
if(isNaN(max_w)){ max_w = 0; }; if(isNaN(max_w)){ max_w = 0; };
@ -1284,31 +1285,31 @@ function paint_graph_status(min_w, max_w, min_c, max_c, inverse_w, inverse_c, er
min_c = parseFloat(min_c); min_c = parseFloat(min_c);
max_w = parseFloat(max_w); max_w = parseFloat(max_w);
max_c = parseFloat(max_c); max_c = parseFloat(max_c);
//inicialize var //inicialize var
var range_min = 0; var range_min = 0;
var range_max = 0; var range_max = 0;
var range_max_min = 0; var range_max_min = 0;
var range_max_min = 0; var range_max_min = 0;
//Find the lowest possible value //Find the lowest possible value
if(min_w < 0 || min_c < 0){ if(min_w < 0 || min_c < 0){
if(min_w < min_c){ if(min_w < min_c){
range_min = min_w - 100; range_min = min_w - 100;
} else { } else {
range_min = min_c - 100; range_min = min_c - 100;
} }
} else if (min_w > 0 || min_c > 0) { } else if (min_w > 0 || min_c > 0) {
if(min_w > min_c){ if(min_w > min_c){
range_max_min = min_w; range_max_min = min_w;
} else { } else {
range_max_min = min_c; range_max_min = min_c;
} }
} else { } else {
if(min_w < min_c){ if(min_w < min_c){
range_min = min_w - 100; range_min = min_w - 100;
} else { } else {
range_min = min_c - 100; range_min = min_c - 100;
} }
} }
@ -1318,7 +1319,7 @@ function paint_graph_status(min_w, max_w, min_c, max_c, inverse_w, inverse_c, er
} else { } else {
range_max = max_c + 100 + range_max_min; range_max = max_c + 100 + range_max_min;
} }
//Controls whether the maximum = 0 is infinite //Controls whether the maximum = 0 is infinite
if((max_w == 0 || max_w == 0.00) && min_w != 0){ if((max_w == 0 || max_w == 0.00) && min_w != 0){
max_w = range_max; max_w = range_max;
@ -1326,10 +1327,10 @@ function paint_graph_status(min_w, max_w, min_c, max_c, inverse_w, inverse_c, er
if((max_c == 0 || max_c == 0.00) && min_c != 0){ if((max_c == 0 || max_c == 0.00) && min_c != 0){
max_c = range_max; max_c = range_max;
} }
//Scale according to the position //Scale according to the position
position = 200 / (range_max-range_min); position = 200 / (range_max-range_min);
//axes //axes
var yScale = d3.scale.linear() var yScale = d3.scale.linear()
.domain([range_min, range_max]) .domain([range_min, range_max])
@ -1344,13 +1345,13 @@ function paint_graph_status(min_w, max_w, min_c, max_c, inverse_w, inverse_c, er
//delete elements //delete elements
svg.selectAll("g").remove(); svg.selectAll("g").remove();
width_x = 201; width_x = 101;
height_x = 50; height_x = 50;
svg.append("g") svg.append("g")
.attr("transform", "translate(200, 150)") .attr("transform", "translate(100, 150)")
.call(yAxis); .call(yAxis);
//legend Normal text //legend Normal text
svg.append("g") svg.append("g")
.attr("width", 300) .attr("width", 300)
@ -1371,14 +1372,14 @@ function paint_graph_status(min_w, max_w, min_c, max_c, inverse_w, inverse_c, er
svg.append("g") svg.append("g")
.append("rect") .append("rect")
.attr("id", "legend_normal") .attr("id", "legend_normal")
.attr("x", width_x + 80) .attr("x", width_x + 80)
.attr("y", height_x - 30) .attr("y", height_x - 30)
.attr("width", 10) .attr("width", 10)
.attr("height", 10) .attr("height", 10)
.style("fill", "#82B92E"); .style("fill", "#82B92E");
//legend Warning text //legend Warning text
svg.append("g") svg.append("g")
.append("text") .append("text")
.attr("x", width_x + 100) .attr("x", width_x + 100)
.attr("y", height_x - 20) .attr("y", height_x - 20)
@ -1393,14 +1394,14 @@ function paint_graph_status(min_w, max_w, min_c, max_c, inverse_w, inverse_c, er
svg.append("g") svg.append("g")
.append("rect") .append("rect")
.attr("id", "legend_warning") .attr("id", "legend_warning")
.attr("x", width_x + 185) .attr("x", width_x + 185)
.attr("y", height_x - 30) .attr("y", height_x - 30)
.attr("width", 10) .attr("width", 10)
.attr("height", 10) .attr("height", 10)
.style("fill", "#ffd731"); .style("fill", "#ffd731");
//legend Critical text //legend Critical text
svg.append("g") svg.append("g")
.append("text") .append("text")
.attr("x", width_x + 205) .attr("x", width_x + 205)
.attr("y", height_x - 20) .attr("y", height_x - 20)
@ -1415,11 +1416,11 @@ function paint_graph_status(min_w, max_w, min_c, max_c, inverse_w, inverse_c, er
svg.append("g") svg.append("g")
.append("rect") .append("rect")
.attr("id", "legend_critical") .attr("id", "legend_critical")
.attr("x", width_x + 285) .attr("x", width_x + 285)
.attr("y", height_x - 30) .attr("y", height_x - 30)
.attr("width", 10) .attr("width", 10)
.attr("height", 10) .attr("height", 10)
.style("fill", "#fc4444"); .style("fill", "#fc4444");
//styles for number and axes //styles for number and axes
svg.selectAll("g .domain") svg.selectAll("g .domain")
@ -1435,89 +1436,87 @@ function paint_graph_status(min_w, max_w, min_c, max_c, inverse_w, inverse_c, er
svg.append("g") svg.append("g")
.append("rect") .append("rect")
.attr("id", "status_rect") .attr("id", "status_rect")
.attr("x", width_x) .attr("x", width_x)
.attr("y", height_x) .attr("y", height_x)
.attr("width", 300) .attr("width", 300)
.attr("height", 200) .attr("height", 200)
.style("fill", "#82B92E"); .style("fill", "#82B92E");
//controls the inverse warning //controls the inverse warning
if(inverse_w == 0){ if(inverse_w == 0){
svg.append("g") svg.append("g")
.append("rect").transition() .append("rect").transition()
.duration(600) .duration(600)
.attr("id", "warning_rect") .attr("id", "warning_rect")
.attr("x", width_x) .attr("x", width_x)
.attr("y", (height_x +(range_max - min_w) * position) - ((max_w - min_w) * position)) .attr("y", (height_x +(range_max - min_w) * position) - ((max_w - min_w) * position))
.attr("width", 300) .attr("width", 300)
.attr("height", ((max_w - min_w) * position)) .attr("height", ((max_w - min_w) * position))
.style("fill", "#ffd731"); .style("fill", "#ffd731");
} }
else { else {
svg.append("g") svg.append("g")
.append("rect").transition() .append("rect").transition()
.duration(600) .duration(600)
.attr("id", "warning_rect") .attr("id", "warning_rect")
.attr("x", width_x) .attr("x", width_x)
.attr("y", height_x + 200 - ((min_w -range_min) * position)) .attr("y", height_x + 200 - ((min_w -range_min) * position))
.attr("width", 300) .attr("width", 300)
.attr("height", (min_w -range_min) * position) .attr("height", (min_w -range_min) * position)
.style("fill", "#ffd731"); .style("fill", "#ffd731");
svg.append("g") svg.append("g")
.append("rect").transition() .append("rect").transition()
.duration(600) .duration(600)
.attr("id", "warning_inverse_rect") .attr("id", "warning_inverse_rect")
.attr("x", width_x) .attr("x", width_x)
.attr("y", height_x) .attr("y", height_x)
.attr("width", 300) .attr("width", 300)
.attr("height", ((range_max - min_w) * position) - ((max_w - min_w) * position)) .attr("height", ((range_max - min_w) * position) - ((max_w - min_w) * position))
.style("fill", "#ffd731"); .style("fill", "#ffd731");
}
} //controls the inverse critical
//controls the inverse critical if(inverse_c == 0){
if(inverse_c == 0){ svg.append("g")
svg.append("g")
.append("rect").transition() .append("rect").transition()
.duration(600) .duration(600)
.attr("id", "critical_rect") .attr("id", "critical_rect")
.attr("x", width_x) .attr("x", width_x)
.attr("y", (height_x + (range_max - min_c) * position) - ((max_c - min_c) * position)) .attr("y", (height_x + (range_max - min_c) * position) - ((max_c - min_c) * position))
.attr("width", 300) .attr("width", 300)
.attr("height", ((max_c - min_c) * position)) .attr("height", ((max_c - min_c) * position))
.style("fill", "#fc4444"); .style("fill", "#fc4444");
} }
else { else {
svg.append("g") svg.append("g")
.append("rect").transition() .append("rect").transition()
.duration(600) .duration(600)
.attr("id", "critical_rect") .attr("id", "critical_rect")
.attr("x", width_x) .attr("x", width_x)
.attr("y", height_x + 200 - ((min_c -range_min) * position)) .attr("y", height_x + 200 - ((min_c -range_min) * position))
.attr("width", 300) .attr("width", 300)
.attr("height", (min_c -range_min) * position) .attr("height", (min_c -range_min) * position)
.style("fill", "#fc4444"); .style("fill", "#fc4444");
svg.append("g") svg.append("g")
.append("rect").transition() .append("rect").transition()
.duration(600) .duration(600)
.attr("id", "critical_inverse_rect") .attr("id", "critical_inverse_rect")
.attr("x", width_x) .attr("x", width_x)
.attr("y", height_x) .attr("y", height_x)
.attr("width", 300) .attr("width", 300)
.attr("height", ((range_max - min_c) * position) - ((max_c - min_c) * position)) .attr("height", ((range_max - min_c) * position) - ((max_c - min_c) * position))
.style("fill", "#fc4444"); .style("fill", "#fc4444");
} }
} }
else { else {
d3.select("#svg_dinamic rect").remove(); d3.select("#svg_dinamic rect").remove();
//create svg //create svg
var svg = d3.select("#svg_dinamic"); var svg = d3.select("#svg_dinamic");
svg.selectAll("g").remove(); svg.selectAll("g").remove();
width_x = 201; width_x = 10;
height_x = 50; height_x = 50;
//message error warning //message error warning
if (error_w == 1) { if (error_w == 1) {
$("#text-max_warning").addClass("input_error"); $("#text-max_warning").addClass("input_error");
@ -1546,9 +1545,8 @@ function paint_graph_status(min_w, max_w, min_c, max_c, inverse_w, inverse_c, er
.style("font-size", 14) .style("font-size", 14)
.style("fill", "red") .style("fill", "red")
.html(message_error_critical) .html(message_error_critical)
.style("text-anchor", "first"); .style("text-anchor", "first");
} }
} }
} }