2019-05-09 16:26:38 +02:00
|
|
|
/* global $ */
|
|
|
|
|
2020-01-24 15:13:42 +01:00
|
|
|
// eslint-disable-next-line no-unused-vars
|
2019-01-30 12:27:18 +01:00
|
|
|
function pandoraFlotPie(
|
|
|
|
graph_id,
|
|
|
|
values,
|
|
|
|
labels,
|
|
|
|
nseries,
|
|
|
|
width,
|
|
|
|
font_size,
|
|
|
|
water_mark,
|
|
|
|
separator,
|
|
|
|
legend_position,
|
|
|
|
height,
|
|
|
|
colors,
|
|
|
|
hide_labels
|
|
|
|
) {
|
2022-05-17 13:20:40 +02:00
|
|
|
height = parseInt(height);
|
|
|
|
|
2019-08-23 10:59:06 +02:00
|
|
|
labels = labels.split(separator);
|
2019-01-30 12:27:18 +01:00
|
|
|
var data = values.split(separator);
|
2016-05-26 08:57:33 +02:00
|
|
|
|
2019-01-30 12:27:18 +01:00
|
|
|
if (colors != "") {
|
|
|
|
colors = colors.split(separator);
|
|
|
|
}
|
2018-10-11 12:57:48 +02:00
|
|
|
|
2019-01-30 12:27:18 +01:00
|
|
|
var pieRadius = 0.9;
|
2016-05-26 08:57:33 +02:00
|
|
|
|
2019-01-30 12:27:18 +01:00
|
|
|
var color = null;
|
|
|
|
for (var i = 0; i < nseries; i++) {
|
|
|
|
if (colors != "") {
|
|
|
|
color = colors[i];
|
|
|
|
}
|
|
|
|
data[i] = { label: labels[i], data: parseFloat(data[i]), color: color };
|
|
|
|
}
|
|
|
|
|
|
|
|
var show_legend = true;
|
|
|
|
if (legend_position == "hidden") {
|
|
|
|
show_legend = false;
|
|
|
|
}
|
|
|
|
|
|
|
|
var conf_pie = {
|
|
|
|
series: {
|
|
|
|
pie: {
|
|
|
|
show: true,
|
|
|
|
radius: pieRadius
|
|
|
|
}
|
|
|
|
},
|
|
|
|
legend: {
|
|
|
|
show: show_legend
|
|
|
|
},
|
|
|
|
grid: {
|
|
|
|
hoverable: true,
|
|
|
|
clickable: true
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
if (hide_labels != false && hide_labels != 0) {
|
|
|
|
conf_pie.series.pie.label = {
|
|
|
|
show: true,
|
|
|
|
radius: 2 / 3,
|
|
|
|
formatter: labelFormatter,
|
|
|
|
threshold: 0.1
|
|
|
|
};
|
|
|
|
} else {
|
|
|
|
conf_pie.series.pie.label = {
|
|
|
|
show: false
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
switch (legend_position) {
|
|
|
|
case "bottom":
|
|
|
|
conf_pie.legend.position = "se";
|
|
|
|
break;
|
|
|
|
case "right":
|
|
|
|
case "inner":
|
|
|
|
conf_pie.legend.container = $("#" + graph_id + "_legend");
|
2020-01-24 15:13:42 +01:00
|
|
|
break;
|
2019-01-30 12:27:18 +01:00
|
|
|
default:
|
2020-01-24 15:13:42 +01:00
|
|
|
// TODO FOR TOP OR LEFT OR RIGHT.
|
2019-01-30 12:27:18 +01:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2022-05-17 13:20:40 +02:00
|
|
|
var discount = 20;
|
|
|
|
if (water_mark) {
|
|
|
|
discount = 40;
|
|
|
|
}
|
|
|
|
|
2019-01-30 12:27:18 +01:00
|
|
|
var plot = $.plot($("#" + graph_id), data, conf_pie);
|
|
|
|
|
|
|
|
var legends = $("#" + graph_id + " .legendLabel");
|
|
|
|
legends.css("font-size", font_size + "pt");
|
|
|
|
|
2022-05-17 13:20:40 +02:00
|
|
|
var tableDiv = $("#" + graph_id + " .legend > div");
|
|
|
|
tableDiv.css("max-height", height - discount + "px");
|
|
|
|
|
|
|
|
var tableLegend = $("#" + graph_id + " .legend table");
|
|
|
|
tableLegend.css("max-height", height - discount + "px");
|
|
|
|
|
2019-01-30 12:27:18 +01:00
|
|
|
// Events
|
|
|
|
$("#" + graph_id).bind("plothover", pieHover);
|
2020-01-24 15:13:42 +01:00
|
|
|
//$("#" + graph_id).bind("plotclick", pieClick);
|
2019-01-30 12:27:18 +01:00
|
|
|
$("#" + graph_id).bind("mouseout", resetInteractivity);
|
|
|
|
$("#" + graph_id).css("margin-left", "auto");
|
|
|
|
$("#" + graph_id).css("margin-right", "auto");
|
|
|
|
|
|
|
|
function pieHover(event, pos, obj) {
|
|
|
|
if (!obj) return;
|
|
|
|
|
2019-08-23 10:59:06 +02:00
|
|
|
var index = obj.seriesIndex;
|
2019-01-30 12:27:18 +01:00
|
|
|
legends.css("color", "#3F3F3D");
|
|
|
|
legends.eq(index).css("color", "");
|
|
|
|
}
|
|
|
|
|
|
|
|
function labelFormatter(label, series) {
|
|
|
|
return (
|
|
|
|
'<div style="font-size:' +
|
|
|
|
font_size +
|
|
|
|
"pt;" +
|
2022-03-31 20:11:52 +02:00
|
|
|
'text-align:center;padding:2px;color:#4a4a4a;">' +
|
2019-01-30 12:27:18 +01:00
|
|
|
label +
|
|
|
|
"<br/>" +
|
|
|
|
series.percent.toFixed(2) +
|
|
|
|
"%</div>"
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Reset styles
|
|
|
|
function resetInteractivity() {
|
2021-04-15 13:55:14 +02:00
|
|
|
legends.css("color", "#3F3F3D");
|
|
|
|
legends.attr("class", "invert_filter");
|
2019-01-30 12:27:18 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
if (water_mark) {
|
|
|
|
set_watermark(
|
|
|
|
graph_id,
|
|
|
|
plot,
|
|
|
|
$("#watermark_image_" + graph_id).attr("src")
|
|
|
|
);
|
|
|
|
}
|
2016-05-26 08:57:33 +02:00
|
|
|
}
|
|
|
|
|
2020-01-24 15:13:42 +01:00
|
|
|
// eslint-disable-next-line no-unused-vars
|
2019-01-30 12:27:18 +01:00
|
|
|
function pandoraFlotPieCustom(
|
|
|
|
graph_id,
|
|
|
|
values,
|
|
|
|
labels,
|
|
|
|
width,
|
|
|
|
font_size,
|
|
|
|
font,
|
|
|
|
water_mark,
|
|
|
|
separator,
|
|
|
|
legend_position,
|
|
|
|
height,
|
|
|
|
colors,
|
|
|
|
legend,
|
|
|
|
background_color
|
|
|
|
) {
|
|
|
|
font = font
|
|
|
|
.split("/")
|
|
|
|
.pop()
|
|
|
|
.split(".")
|
|
|
|
.shift();
|
2019-08-23 10:59:06 +02:00
|
|
|
labels = labels.split(separator);
|
|
|
|
legend = legend.split(separator);
|
2019-01-30 12:27:18 +01:00
|
|
|
var data = values.split(separator);
|
|
|
|
var no_data = 0;
|
|
|
|
if (colors != "") {
|
|
|
|
colors = colors.split(separator);
|
|
|
|
}
|
2019-08-23 10:59:06 +02:00
|
|
|
|
2019-01-30 12:27:18 +01:00
|
|
|
var color = null;
|
|
|
|
for (var i = 0; i < data.length; i++) {
|
|
|
|
if (colors != "") {
|
|
|
|
color = colors[i];
|
|
|
|
}
|
|
|
|
var datos = data[i];
|
|
|
|
data[i] = { label: labels[i], data: parseFloat(data[i]), color: color };
|
|
|
|
if (!datos) no_data++;
|
|
|
|
}
|
|
|
|
|
|
|
|
var label_conf;
|
|
|
|
var show_legend = true;
|
|
|
|
|
2021-07-13 17:26:03 +02:00
|
|
|
// Set default value if not come like a number.
|
|
|
|
if (isNaN(width) === true) {
|
|
|
|
width = 451;
|
|
|
|
}
|
|
|
|
|
2019-01-30 12:27:18 +01:00
|
|
|
if (width <= 450) {
|
|
|
|
show_legend = false;
|
|
|
|
label_conf = {
|
|
|
|
show: true,
|
2019-08-23 10:59:06 +02:00
|
|
|
radius: 5 / 8,
|
2019-01-30 12:27:18 +01:00
|
|
|
formatter: function(label, series) {
|
|
|
|
return (
|
|
|
|
'<div style="font-size:' +
|
|
|
|
font_size +
|
2019-08-23 10:59:06 +02:00
|
|
|
"pt; font-weight:bolder;" +
|
|
|
|
"text-align:center;padding:2px;color:rgb(63, 63, 61)" +
|
|
|
|
'">' +
|
|
|
|
label +
|
|
|
|
":<br>" +
|
|
|
|
series.data[0][1] +
|
|
|
|
"</div>"
|
2019-01-30 12:27:18 +01:00
|
|
|
);
|
|
|
|
},
|
|
|
|
background: {
|
2019-08-23 10:59:06 +02:00
|
|
|
opacity: 0.5
|
2019-01-30 12:27:18 +01:00
|
|
|
}
|
|
|
|
};
|
2019-08-23 10:59:06 +02:00
|
|
|
} else {
|
|
|
|
label_conf = {
|
|
|
|
show: false
|
|
|
|
};
|
2019-01-30 12:27:18 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
var conf_pie = {
|
|
|
|
series: {
|
|
|
|
pie: {
|
|
|
|
show: true,
|
|
|
|
radius: 3 / 4,
|
2019-08-23 10:59:06 +02:00
|
|
|
innerRadius: 0.4,
|
|
|
|
label: label_conf
|
2019-01-30 12:27:18 +01:00
|
|
|
}
|
|
|
|
},
|
|
|
|
legend: {
|
|
|
|
show: show_legend
|
|
|
|
},
|
|
|
|
grid: {
|
|
|
|
hoverable: true,
|
|
|
|
clickable: true
|
|
|
|
}
|
|
|
|
};
|
|
|
|
if (
|
|
|
|
/Android|webOS|iPhone|iPad|iPod|BlackBerry|IEMobile|Opera Mini/i.test(
|
|
|
|
navigator.userAgent
|
|
|
|
)
|
|
|
|
) {
|
|
|
|
conf_pie.series.pie.label = { show: false };
|
|
|
|
}
|
|
|
|
|
2021-07-13 17:26:03 +02:00
|
|
|
// Avoid issues with 0 width values.
|
|
|
|
$("#" + graph_id).width(width);
|
|
|
|
|
2019-01-30 12:27:18 +01:00
|
|
|
var plot = $.plot($("#" + graph_id), data, conf_pie);
|
|
|
|
if (no_data == data.length) {
|
|
|
|
$("#" + graph_id + " .overlay").remove();
|
|
|
|
$("#" + graph_id + " .base").remove();
|
|
|
|
$("#" + graph_id).prepend(
|
|
|
|
"<img style='width:50%;' src='images/no_data_toshow.png' />"
|
|
|
|
);
|
|
|
|
}
|
|
|
|
var legends = $("#" + graph_id + " .legendLabel");
|
|
|
|
|
|
|
|
if (background_color == "transparent") {
|
|
|
|
$(".legend>table").css("background-color", "");
|
|
|
|
$(".legend>div").css("background-color", "");
|
2021-06-10 10:19:11 +02:00
|
|
|
$(".legend>table").css("color", "#000");
|
2019-01-30 12:27:18 +01:00
|
|
|
} else if (background_color == "white") {
|
|
|
|
$(".legend>table").css("background-color", "white");
|
|
|
|
$(".legend>table").css("color", "black");
|
|
|
|
} else if (background_color == "black") {
|
|
|
|
$(".legend>table").css("background-color", "black");
|
|
|
|
$(".legend>table").css("color", "#aaa");
|
2021-04-09 11:52:28 +02:00
|
|
|
} else if (background_color == "black_theme") {
|
|
|
|
$(".legend>table").css("background-color", "#222");
|
|
|
|
$(".legend>div").css("background-color", "#222");
|
|
|
|
$(".legend>table").css("color", "#fff !important");
|
2019-01-30 12:27:18 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
$(".legend").hover(function() {
|
|
|
|
return false;
|
|
|
|
});
|
|
|
|
|
|
|
|
// Events
|
|
|
|
$("#" + graph_id).bind("plothover", pieHover);
|
|
|
|
$("#" + graph_id).bind("plotclick", Clickpie);
|
|
|
|
$("#" + graph_id).bind("mouseout", resetInteractivity);
|
|
|
|
$("#" + graph_id).css("margin-left", "auto");
|
|
|
|
$("#" + graph_id).css("margin-right", "auto");
|
|
|
|
|
|
|
|
function pieHover(event, pos, obj) {
|
|
|
|
if (!obj) return;
|
|
|
|
|
2019-08-23 10:59:06 +02:00
|
|
|
var index = obj.seriesIndex;
|
2021-04-09 11:52:28 +02:00
|
|
|
if (background_color == "black_theme") {
|
|
|
|
legends.css("color", "#fff");
|
|
|
|
} else {
|
|
|
|
legends.css("color", "#3F3F3D");
|
|
|
|
}
|
2019-01-30 12:27:18 +01:00
|
|
|
legends.eq(index).css("color", "");
|
|
|
|
}
|
|
|
|
|
|
|
|
function Clickpie(event, pos, obj) {
|
|
|
|
if (!obj) return;
|
2019-08-23 10:59:06 +02:00
|
|
|
var percent = parseFloat(obj.series.percent).toFixed(2);
|
|
|
|
var valor = parseFloat(obj.series.data[0][1]);
|
2019-01-30 12:27:18 +01:00
|
|
|
|
2019-08-23 10:59:06 +02:00
|
|
|
var value = "";
|
2019-01-30 12:27:18 +01:00
|
|
|
if (valor > 1000000) {
|
|
|
|
value = Math.round((valor / 1000000) * 100) / 100;
|
|
|
|
value = value + "M";
|
|
|
|
} else {
|
|
|
|
if (valor > 1000) {
|
|
|
|
value = Math.round((valor / 1000) * 100) / 100;
|
|
|
|
value = value + "K";
|
|
|
|
} else value = valor;
|
|
|
|
}
|
|
|
|
|
|
|
|
alert("" + obj.series.label + ": " + value + " (" + percent + "%)");
|
|
|
|
}
|
|
|
|
|
|
|
|
// Reset styles
|
|
|
|
function resetInteractivity() {
|
|
|
|
legends.each(function() {
|
|
|
|
// fix the widths so they don't jump around
|
|
|
|
$(this).css("color", "#3F3F3D");
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
if (water_mark) {
|
|
|
|
set_watermark(
|
|
|
|
graph_id,
|
|
|
|
plot,
|
|
|
|
$("#watermark_image_" + graph_id).attr("src")
|
|
|
|
);
|
|
|
|
}
|
2016-05-26 08:57:33 +02:00
|
|
|
}
|
|
|
|
|
2020-01-24 15:13:42 +01:00
|
|
|
// eslint-disable-next-line no-unused-vars
|
2019-01-30 12:27:18 +01:00
|
|
|
function pandoraFlotHBars(
|
|
|
|
graph_id,
|
|
|
|
values,
|
|
|
|
labels,
|
|
|
|
maxvalue,
|
|
|
|
water_mark,
|
|
|
|
separator,
|
|
|
|
separator2,
|
|
|
|
font,
|
|
|
|
font_size,
|
|
|
|
background_color,
|
|
|
|
tick_color,
|
|
|
|
min,
|
|
|
|
max
|
|
|
|
) {
|
|
|
|
var colors_data = [
|
2019-06-04 14:08:07 +02:00
|
|
|
"#e63c52",
|
2019-01-30 12:27:18 +01:00
|
|
|
"#FFA631",
|
2019-06-04 14:08:07 +02:00
|
|
|
"#f3b200",
|
2021-12-28 12:38:22 +01:00
|
|
|
"#4a83f3",
|
2019-01-30 12:27:18 +01:00
|
|
|
"#F2919D",
|
2019-06-04 14:08:07 +02:00
|
|
|
"#82b92e"
|
2019-01-30 12:27:18 +01:00
|
|
|
];
|
|
|
|
values = values.split(separator2);
|
|
|
|
font = font
|
|
|
|
.split("/")
|
|
|
|
.pop()
|
|
|
|
.split(".")
|
|
|
|
.shift();
|
|
|
|
var datas = new Array();
|
|
|
|
for (i = 0; i < values.length; i++) {
|
|
|
|
var serie = values[i].split(separator);
|
|
|
|
|
|
|
|
var aux = new Array();
|
2020-01-24 15:13:42 +01:00
|
|
|
for (var j = 0; j < serie.length; j++) {
|
2019-01-30 12:27:18 +01:00
|
|
|
var aux2 = parseFloat(serie[j]);
|
|
|
|
aux.push([aux2, j]);
|
|
|
|
datas.push({
|
|
|
|
data: [[aux2, j]],
|
|
|
|
color: colors_data[j]
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
var labels_total = new Array();
|
|
|
|
labels = labels.split(separator);
|
2020-01-24 15:13:42 +01:00
|
|
|
for (var i = 0; i < labels.length; i++) {
|
2019-01-30 12:27:18 +01:00
|
|
|
labels_total.push([i, labels[i]]);
|
|
|
|
}
|
|
|
|
|
2021-04-09 11:52:28 +02:00
|
|
|
var ycolor = "rgb(84, 84, 84)";
|
|
|
|
|
|
|
|
if (background_color == "#222") {
|
|
|
|
var ycolor = "#fff";
|
|
|
|
}
|
2019-01-30 12:27:18 +01:00
|
|
|
var options = {
|
|
|
|
series: {
|
|
|
|
bars: {
|
|
|
|
show: true,
|
|
|
|
barWidth: 0.75,
|
|
|
|
align: "center",
|
|
|
|
lineWidth: 1,
|
|
|
|
fill: 1,
|
|
|
|
horizontal: true
|
|
|
|
}
|
|
|
|
},
|
|
|
|
grid: {
|
|
|
|
hoverable: true,
|
|
|
|
borderWidth: 1,
|
|
|
|
tickColor: tick_color,
|
|
|
|
borderColor: "#C1C1C1",
|
|
|
|
backgroundColor: { colors: [background_color, background_color] }
|
|
|
|
},
|
|
|
|
xaxis: {
|
|
|
|
color: tick_color,
|
|
|
|
axisLabelUseCanvas: true,
|
|
|
|
axisLabelFontSizePixels: font_size,
|
2021-06-10 10:19:11 +02:00
|
|
|
axisLabelFontFamily: "lato",
|
2019-01-30 12:27:18 +01:00
|
|
|
tickFormatter: xFormatter
|
|
|
|
},
|
|
|
|
yaxis: {
|
|
|
|
font: {
|
|
|
|
size: font_size + 2,
|
2021-04-09 11:52:28 +02:00
|
|
|
color: ycolor,
|
2021-06-10 10:19:11 +02:00
|
|
|
family: "lato"
|
2019-01-30 12:27:18 +01:00
|
|
|
},
|
|
|
|
ticks: yFormatter
|
|
|
|
},
|
|
|
|
legend: {
|
|
|
|
show: false
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
// Fixed to avoid the graphs with all 0 datas
|
|
|
|
// the X axis show negative part instead to
|
|
|
|
// show the axis only the positive part.
|
|
|
|
if (maxvalue == 0) {
|
|
|
|
options["yaxis"]["min"] = 0;
|
|
|
|
// Fixed the values with a lot of decimals in the situation
|
|
|
|
// with all 0 values.
|
|
|
|
options["yaxis"]["tickDecimals"] = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (max) {
|
|
|
|
options["xaxis"]["max"] = max;
|
|
|
|
}
|
|
|
|
if (min) {
|
|
|
|
options["xaxis"]["min"] = min;
|
|
|
|
}
|
|
|
|
|
|
|
|
var plot = $.plot($("#" + graph_id), datas, options);
|
|
|
|
|
|
|
|
$("#" + graph_id).HUseTooltip();
|
|
|
|
$("#" + graph_id).css("margin-left", "auto");
|
|
|
|
$("#" + graph_id).css("margin-right", "auto");
|
|
|
|
|
2020-01-24 15:13:42 +01:00
|
|
|
// v, axis;
|
|
|
|
function yFormatter() {
|
|
|
|
var format = new Array();
|
|
|
|
for (var i = 0; i < labels_total.length; i++) {
|
2019-01-30 12:27:18 +01:00
|
|
|
var label = labels_total[i][1];
|
|
|
|
var div_attributes =
|
|
|
|
'style="font-size:' +
|
|
|
|
font_size +
|
|
|
|
"pt !important;" +
|
2022-01-10 10:22:59 +01:00
|
|
|
"margin: 0; max-width: 200px;" +
|
|
|
|
"margin-right:5px;" +
|
2022-05-17 13:20:40 +02:00
|
|
|
"margin-left: -1.5em;" +
|
|
|
|
"text-align: right;" +
|
2022-01-10 10:22:59 +01:00
|
|
|
"text-overflow: ellipsis;" +
|
|
|
|
"overflow: hidden;" +
|
|
|
|
"white-space: pre;";
|
2019-01-30 12:27:18 +01:00
|
|
|
|
|
|
|
if (label.indexOf("<br>") != -1) {
|
2022-05-17 13:20:40 +02:00
|
|
|
var label_array = label.split("<br>");
|
|
|
|
label = label_array[0] + label_array[1];
|
2019-01-30 12:27:18 +01:00
|
|
|
}
|
|
|
|
|
2022-01-10 10:22:59 +01:00
|
|
|
div_attributes += '" title="' + label + '" style="overflow: hidden;"';
|
2019-01-30 12:27:18 +01:00
|
|
|
|
|
|
|
format.push([i, "<div " + div_attributes + ">" + label + "</div>"]);
|
|
|
|
}
|
|
|
|
return format;
|
|
|
|
}
|
|
|
|
|
2020-01-24 15:13:42 +01:00
|
|
|
// v, axis;
|
|
|
|
function xFormatter(v) {
|
|
|
|
var label = parseFloat(v);
|
2020-04-03 10:34:54 +02:00
|
|
|
|
|
|
|
const unit_prefixes = ["K", "M", "G"];
|
2020-04-03 10:41:24 +02:00
|
|
|
var unit_prefix = "";
|
2020-04-03 10:34:54 +02:00
|
|
|
var i = 0;
|
|
|
|
|
|
|
|
while (label >= 1000 && i < 3) {
|
|
|
|
label = label / 1000;
|
|
|
|
unit_prefix = unit_prefixes[i];
|
|
|
|
i++;
|
|
|
|
}
|
2020-01-24 15:13:42 +01:00
|
|
|
var text = label.toLocaleString();
|
2020-04-03 10:34:54 +02:00
|
|
|
|
|
|
|
text = text + unit_prefix;
|
2019-01-30 12:27:18 +01:00
|
|
|
|
|
|
|
return (
|
|
|
|
'<div style="font-size:' +
|
|
|
|
font_size +
|
|
|
|
'pt !important;">' +
|
|
|
|
text +
|
|
|
|
"</div>"
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (water_mark) {
|
|
|
|
set_watermark(
|
|
|
|
graph_id,
|
|
|
|
plot,
|
|
|
|
$("#watermark_image_" + graph_id).attr("src")
|
|
|
|
);
|
|
|
|
}
|
2016-05-26 08:57:33 +02:00
|
|
|
}
|
|
|
|
|
2019-01-30 12:27:18 +01:00
|
|
|
var previousPoint = null,
|
|
|
|
previousLabel = null;
|
|
|
|
|
|
|
|
$.fn.HUseTooltip = function() {
|
|
|
|
$(this).bind("plothover", function(event, pos, item) {
|
|
|
|
if (item) {
|
|
|
|
if (
|
|
|
|
previousLabel != item.series.label ||
|
|
|
|
previousPoint != item.seriesIndex
|
|
|
|
) {
|
|
|
|
previousPoint = item.seriesIndex;
|
|
|
|
previousLabel = item.series.label;
|
|
|
|
$("#tooltip").remove();
|
|
|
|
|
|
|
|
var x = item.datapoint[0];
|
2020-01-24 15:13:42 +01:00
|
|
|
// var y = item.datapoint[1];
|
2019-01-30 12:27:18 +01:00
|
|
|
|
|
|
|
var color = item.series.color;
|
2020-11-25 17:29:09 +01:00
|
|
|
showTooltip(
|
|
|
|
item.pageX,
|
|
|
|
item.pageY,
|
|
|
|
color,
|
|
|
|
"<strong>" + x + "</strong>"
|
|
|
|
);
|
2019-01-30 12:27:18 +01:00
|
|
|
}
|
|
|
|
} else {
|
|
|
|
$("#tooltip").remove();
|
|
|
|
previousPoint = null;
|
|
|
|
}
|
|
|
|
});
|
2016-05-26 08:57:33 +02:00
|
|
|
};
|
2020-03-26 12:29:38 +01:00
|
|
|
|
2019-01-30 12:27:18 +01:00
|
|
|
$.fn.VUseTooltip = function() {
|
|
|
|
$(this).bind("plothover", function(event, pos, item) {
|
|
|
|
if (item) {
|
|
|
|
if (
|
|
|
|
previousLabel != item.series.label ||
|
2020-03-26 12:29:38 +01:00
|
|
|
previousPoint != item.dataIndex
|
2019-01-30 12:27:18 +01:00
|
|
|
) {
|
2020-03-26 12:29:38 +01:00
|
|
|
previousPoint = item.dataIndex;
|
2019-01-30 12:27:18 +01:00
|
|
|
previousLabel = item.series.label;
|
|
|
|
$("#tooltip").remove();
|
|
|
|
|
2020-10-07 16:03:52 +02:00
|
|
|
//var x = item.datapoint[0];
|
2020-03-26 12:29:38 +01:00
|
|
|
|
2019-01-30 12:27:18 +01:00
|
|
|
var y = item.datapoint[1];
|
2020-03-26 12:29:38 +01:00
|
|
|
if (typeof y != "string") {
|
|
|
|
y = number_format(y, false, "", 2, 1000);
|
|
|
|
}
|
2019-01-30 12:27:18 +01:00
|
|
|
|
|
|
|
var color = item.series.color;
|
2020-03-26 12:29:38 +01:00
|
|
|
|
|
|
|
/*
|
|
|
|
"<strong>" +
|
|
|
|
item.series.label +
|
|
|
|
"</strong><br>" +
|
|
|
|
item.series.xaxis.ticks[x].label +
|
|
|
|
" : <strong>" +
|
|
|
|
y +
|
|
|
|
"</strong>"
|
|
|
|
*/
|
|
|
|
|
|
|
|
showTooltip(
|
|
|
|
item.pageX,
|
|
|
|
item.pageY,
|
|
|
|
color,
|
|
|
|
"<strong>" + item.series.label + " : " + y + "</strong>"
|
|
|
|
);
|
2019-01-30 12:27:18 +01:00
|
|
|
}
|
|
|
|
} else {
|
|
|
|
$("#tooltip").remove();
|
|
|
|
previousPoint = null;
|
|
|
|
}
|
|
|
|
});
|
2016-05-26 08:57:33 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
function showTooltip(x, y, color, contents) {
|
2019-01-30 12:27:18 +01:00
|
|
|
$('<div id="tooltip">' + contents + "</div>")
|
|
|
|
.css({
|
|
|
|
position: "absolute",
|
|
|
|
display: "none",
|
|
|
|
top: y,
|
|
|
|
left: x,
|
|
|
|
border: "2px solid " + color,
|
|
|
|
padding: "3px",
|
|
|
|
"font-size": "9px",
|
|
|
|
"border-radius": "5px",
|
|
|
|
"background-color": "#fff",
|
2021-04-09 11:29:26 +02:00
|
|
|
color: "#111",
|
2019-01-30 12:27:18 +01:00
|
|
|
opacity: 0.9
|
|
|
|
})
|
|
|
|
.appendTo("body")
|
|
|
|
.fadeIn(200);
|
2016-05-26 08:57:33 +02:00
|
|
|
}
|
|
|
|
|
2020-01-24 15:13:42 +01:00
|
|
|
// eslint-disable-next-line no-unused-vars
|
2020-03-26 12:29:38 +01:00
|
|
|
function pandoraFlotVBars(settings) {
|
|
|
|
settings = JSON.parse(atob(settings));
|
|
|
|
|
|
|
|
var unit = settings.generals.unit;
|
|
|
|
var divisor = settings.generals.divisor;
|
|
|
|
|
|
|
|
var datas = [];
|
|
|
|
var ticks = [];
|
|
|
|
var labels = [];
|
|
|
|
settings.data.forEach(function(element, index) {
|
|
|
|
var color = element.color;
|
|
|
|
if (settings.generals.arrayColors) {
|
|
|
|
if (settings.generals.arrayColors[index] != undefined) {
|
|
|
|
color = settings.generals.arrayColors[index].color;
|
|
|
|
}
|
|
|
|
}
|
2019-01-30 12:27:18 +01:00
|
|
|
|
2020-03-26 12:29:38 +01:00
|
|
|
datas.push({
|
|
|
|
label: element.tick,
|
|
|
|
color: color,
|
|
|
|
data: [[index, element.data]]
|
|
|
|
});
|
2019-01-30 12:27:18 +01:00
|
|
|
|
2020-03-26 12:29:38 +01:00
|
|
|
if (settings.generals.forceTicks === true) {
|
|
|
|
ticks.push([index, element.tick]);
|
|
|
|
} else {
|
|
|
|
ticks.push([element.tick]);
|
2019-01-30 12:27:18 +01:00
|
|
|
}
|
|
|
|
|
2020-03-26 12:29:38 +01:00
|
|
|
labels.push([index, element.tick]);
|
|
|
|
});
|
|
|
|
|
|
|
|
var formatterTicks = "";
|
|
|
|
if (settings.generals.forceTicks === true) {
|
|
|
|
formatterTicks = "";
|
|
|
|
} else {
|
|
|
|
var ticksformatter = ticks;
|
|
|
|
ticks = null;
|
|
|
|
formatterTicks = function(v) {
|
|
|
|
return ticksformatter[Math.round(v)];
|
|
|
|
};
|
2019-01-30 12:27:18 +01:00
|
|
|
}
|
2021-06-10 10:19:11 +02:00
|
|
|
settings.x.font.family = "lato";
|
|
|
|
settings.y.font.family = "lato";
|
|
|
|
settings.y.title.fontFamily = "lato";
|
2019-01-30 12:27:18 +01:00
|
|
|
var options = {
|
|
|
|
series: {
|
|
|
|
bars: {
|
2020-03-26 12:29:38 +01:00
|
|
|
show: settings.seriesBars.show,
|
|
|
|
lineWidth: settings.seriesBars.lineWidth,
|
|
|
|
fill: settings.seriesBars.fill,
|
|
|
|
fillColor: settings.seriesBars.fillColor
|
2019-01-30 12:27:18 +01:00
|
|
|
}
|
|
|
|
},
|
2020-03-26 12:29:38 +01:00
|
|
|
bars: {
|
|
|
|
align: settings.bars.align,
|
|
|
|
barWidth: settings.bars.barWidth,
|
|
|
|
horizontal: settings.bars.horizontal
|
|
|
|
},
|
2019-01-30 12:27:18 +01:00
|
|
|
xaxis: {
|
2020-03-26 12:29:38 +01:00
|
|
|
axisLabel: settings.x.title.title,
|
2019-01-30 12:27:18 +01:00
|
|
|
axisLabelUseCanvas: true,
|
2020-03-26 12:29:38 +01:00
|
|
|
axisLabelFontSizePixels: settings.x.title.fontSize,
|
|
|
|
axisLabelFontFamily: settings.x.title.fontFamily,
|
|
|
|
axisLabelPadding: settings.x.title.padding,
|
|
|
|
font: {
|
|
|
|
size: settings.x.font.size,
|
|
|
|
lineHeight: settings.x.font.lineHeight,
|
|
|
|
style: settings.x.font.style,
|
|
|
|
weight: settings.x.font.weight,
|
|
|
|
family: settings.x.font.family,
|
|
|
|
variant: settings.x.font.variant,
|
|
|
|
color: settings.x.font.color
|
|
|
|
},
|
|
|
|
show: settings.x.show,
|
|
|
|
position: settings.x.position,
|
|
|
|
color: settings.x.color,
|
|
|
|
ticks: ticks,
|
|
|
|
tickFormatter: formatterTicks,
|
|
|
|
labelWidth: settings.x.labelWidth,
|
|
|
|
labelHeight: settings.x.labelHeight
|
2019-01-30 12:27:18 +01:00
|
|
|
},
|
|
|
|
yaxis: {
|
2020-03-26 12:29:38 +01:00
|
|
|
axisLabel: settings.y.title.title,
|
2019-01-30 12:27:18 +01:00
|
|
|
axisLabelUseCanvas: true,
|
2020-03-26 12:29:38 +01:00
|
|
|
axisLabelFontSizePixels: settings.y.title.fontSize,
|
|
|
|
axisLabelFontFamily: settings.y.title.fontFamily,
|
|
|
|
axisLabelPadding: settings.y.title.padding,
|
|
|
|
font: {
|
|
|
|
size: settings.y.font.size,
|
|
|
|
lineHeight: settings.y.font.lineHeight,
|
|
|
|
style: settings.y.font.style,
|
|
|
|
weight: settings.y.font.weight,
|
|
|
|
family: settings.y.font.family,
|
|
|
|
variant: settings.y.font.variant,
|
|
|
|
color: settings.y.font.color
|
|
|
|
},
|
|
|
|
show: settings.y.show,
|
|
|
|
position: settings.y.position,
|
|
|
|
color: settings.y.color,
|
2020-01-24 15:13:42 +01:00
|
|
|
tickFormatter: function(v) {
|
2020-03-26 12:29:38 +01:00
|
|
|
var formatted = v;
|
|
|
|
if (typeof formatted != "string") {
|
|
|
|
formatted = number_format(v, false, unit, 2, divisor);
|
|
|
|
}
|
2019-01-30 12:27:18 +01:00
|
|
|
|
2020-03-26 12:29:38 +01:00
|
|
|
return formatted;
|
|
|
|
},
|
|
|
|
labelWidth: settings.y.labelWidth,
|
|
|
|
labelHeight: settings.y.labelHeight,
|
|
|
|
reserveSpace: true
|
2019-01-30 12:27:18 +01:00
|
|
|
},
|
|
|
|
legend: {
|
2020-03-26 12:29:38 +01:00
|
|
|
// TODO: settings.
|
|
|
|
show: false
|
2019-01-30 12:27:18 +01:00
|
|
|
},
|
|
|
|
grid: {
|
2020-03-26 12:29:38 +01:00
|
|
|
show: settings.grid.show,
|
|
|
|
aboveData: settings.grid.aboveData,
|
|
|
|
color: settings.grid.color,
|
|
|
|
backgroundColor: settings.grid.backgroundColor,
|
|
|
|
margin: settings.grid.margin,
|
|
|
|
labelMargin: settings.grid.labelMargin,
|
|
|
|
axisMargin: settings.grid.axisMargin,
|
|
|
|
markings: settings.grid.markings,
|
|
|
|
borderWidth: settings.grid.borderWidth,
|
|
|
|
borderColor: settings.grid.borderColor,
|
|
|
|
minBorderMargin: settings.grid.minBorderMargin,
|
|
|
|
clickable: settings.grid.clickable,
|
|
|
|
hoverable: settings.grid.hoverable,
|
|
|
|
autoHighlight: settings.grid.autoHighlight,
|
|
|
|
mouseActiveRadius: settings.grid.mouseActiveRadius
|
2019-01-30 12:27:18 +01:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2020-03-26 12:29:38 +01:00
|
|
|
$.plot($("#" + settings.graphId), datas, options);
|
2019-01-30 12:27:18 +01:00
|
|
|
|
2020-03-26 12:29:38 +01:00
|
|
|
// Hover in bars graph.
|
|
|
|
$("#" + settings.graphId).VUseTooltip();
|
2019-01-30 12:27:18 +01:00
|
|
|
}
|
2016-05-26 08:57:33 +02:00
|
|
|
|
2020-01-24 15:13:42 +01:00
|
|
|
// eslint-disable-next-line no-unused-vars
|
2019-01-30 12:27:18 +01:00
|
|
|
function pandoraFlotSlicebar(
|
|
|
|
graph_id,
|
|
|
|
values,
|
|
|
|
datacolor,
|
|
|
|
legend,
|
|
|
|
intervaltick,
|
|
|
|
font,
|
|
|
|
font_size,
|
|
|
|
separator,
|
|
|
|
separator2,
|
|
|
|
id_agent,
|
|
|
|
full_legend,
|
|
|
|
not_interactive,
|
2019-10-11 09:04:13 +02:00
|
|
|
show_date,
|
2020-03-24 10:12:14 +01:00
|
|
|
datelimit,
|
|
|
|
server_id
|
2019-01-30 12:27:18 +01:00
|
|
|
) {
|
|
|
|
values = values.split(separator2);
|
|
|
|
legend = legend.split(separator);
|
|
|
|
datacolor = datacolor.split(separator);
|
|
|
|
|
|
|
|
if (full_legend != false) {
|
|
|
|
full_legend = full_legend.split(separator);
|
|
|
|
}
|
|
|
|
|
2020-01-15 14:28:43 +01:00
|
|
|
font_size = parseInt(font_size);
|
2021-06-10 10:19:11 +02:00
|
|
|
font = font
|
|
|
|
.split("/")
|
|
|
|
.pop()
|
|
|
|
.split(".")
|
|
|
|
.shift();
|
|
|
|
|
2019-01-30 12:27:18 +01:00
|
|
|
// Check possible adapt_keys on classes
|
|
|
|
check_adaptions(graph_id);
|
|
|
|
|
|
|
|
var datas = new Array();
|
|
|
|
|
2019-06-24 17:17:50 +02:00
|
|
|
for (var i = 0; i < values.length; i++) {
|
2019-01-30 12:27:18 +01:00
|
|
|
var serie = values[i].split(separator);
|
|
|
|
|
|
|
|
var aux = new Array();
|
2019-10-11 09:04:13 +02:00
|
|
|
aux.push([parseInt(serie[0]), 0]);
|
2018-06-12 16:37:41 +02:00
|
|
|
|
2019-01-30 12:27:18 +01:00
|
|
|
datas.push({
|
|
|
|
data: aux,
|
|
|
|
bars: {
|
|
|
|
show: true,
|
|
|
|
fill: 1,
|
|
|
|
fillColor: { colors: [{ opacity: 1 }, { opacity: 1 }] },
|
|
|
|
lineWidth: 0,
|
|
|
|
horizontal: true,
|
|
|
|
steps: false,
|
|
|
|
barWidth: 24 * 60 * 60 * 600
|
|
|
|
},
|
|
|
|
color: datacolor[i]
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
var regex = /visual_console/;
|
|
|
|
var match = regex.exec(window.location.href);
|
|
|
|
|
|
|
|
var options = {
|
|
|
|
series: {
|
|
|
|
stack: true,
|
|
|
|
bars: {
|
|
|
|
align: "center"
|
|
|
|
}
|
|
|
|
},
|
|
|
|
grid: {
|
2022-05-25 09:06:22 +02:00
|
|
|
borderWidth: 0,
|
|
|
|
borderColor: "transparent",
|
2019-01-30 12:27:18 +01:00
|
|
|
tickColor: "#fff"
|
|
|
|
},
|
|
|
|
xaxes: [
|
|
|
|
{
|
2022-05-25 09:06:22 +02:00
|
|
|
show: show_date,
|
2019-01-30 12:27:18 +01:00
|
|
|
tickFormatter: xFormatter,
|
|
|
|
color: "",
|
|
|
|
tickSize: intervaltick,
|
2021-06-25 12:56:03 +02:00
|
|
|
tickLength: 0
|
2019-01-30 12:27:18 +01:00
|
|
|
}
|
|
|
|
],
|
|
|
|
yaxes: [
|
|
|
|
{
|
|
|
|
show: false,
|
|
|
|
tickLength: 0
|
|
|
|
}
|
|
|
|
],
|
|
|
|
legend: {
|
|
|
|
show: false
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
if (match == null && not_interactive == 0) {
|
|
|
|
options.grid["hoverable"] = true;
|
|
|
|
options.grid["clickable"] = true;
|
|
|
|
} else {
|
|
|
|
options.grid["hoverable"] = false;
|
|
|
|
options.grid["clickable"] = false;
|
|
|
|
}
|
|
|
|
|
|
|
|
$.plot($("#" + graph_id), datas, options);
|
|
|
|
|
2021-06-25 12:56:03 +02:00
|
|
|
// Added for correct handle of the font size.
|
|
|
|
// xaxes-yaxes object not handle font-size properly.
|
|
|
|
$(".flot-x-axis .flot-tick-label").css("font-size", font_size);
|
|
|
|
|
2020-01-15 14:28:43 +01:00
|
|
|
if (match == null && not_interactive == 0) {
|
2019-01-30 12:27:18 +01:00
|
|
|
// 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 = ">";
|
|
|
|
}
|
2016-05-26 08:57:33 +02:00
|
|
|
|
2019-01-30 12:27:18 +01:00
|
|
|
$("#extra_" + graph_id).text(from + "-" + to);
|
|
|
|
var extra_width = parseInt(
|
|
|
|
$("#extra_" + graph_id)
|
|
|
|
.css("width")
|
|
|
|
.split("px")[0]
|
|
|
|
);
|
2019-10-11 09:04:13 +02:00
|
|
|
|
|
|
|
$("#extra_" + graph_id).css(
|
|
|
|
"left",
|
|
|
|
parseInt(pos.pageX - extra_width - 200) + "px"
|
|
|
|
);
|
2019-01-30 12:27:18 +01:00
|
|
|
$("#extra_" + graph_id).show();
|
|
|
|
}
|
|
|
|
});
|
2018-10-16 15:32:31 +02:00
|
|
|
|
2019-01-30 12:27:18 +01:00
|
|
|
$("#" + graph_id).bind("plotclick", function(event, pos, item) {
|
|
|
|
if (item) {
|
|
|
|
//from time
|
|
|
|
var from = legend[item.seriesIndex];
|
|
|
|
//to time
|
|
|
|
var to = legend[item.seriesIndex + 1];
|
|
|
|
//current date
|
|
|
|
var dateObj = new Date();
|
|
|
|
|
2020-01-24 15:13:42 +01:00
|
|
|
var newdate = "";
|
|
|
|
var newdate2 = "";
|
2019-01-30 12:27:18 +01:00
|
|
|
if (full_legend != "") {
|
|
|
|
newdate = full_legend[item.seriesIndex];
|
|
|
|
newdate2 = full_legend[item.seriesIndex + 1];
|
|
|
|
} else {
|
|
|
|
var month = dateObj.getUTCMonth() + 1; //months from 1-12
|
|
|
|
var day = dateObj.getUTCDate();
|
|
|
|
var year = dateObj.getUTCFullYear();
|
|
|
|
newdate = year + "/" + month + "/" + day;
|
|
|
|
}
|
2018-10-16 15:32:31 +02:00
|
|
|
|
2019-01-30 12:27:18 +01:00
|
|
|
if (!to) {
|
|
|
|
to = "23:59";
|
|
|
|
}
|
2018-05-10 08:43:09 +02:00
|
|
|
|
2019-12-10 15:29:35 +01:00
|
|
|
var url_filters = {
|
|
|
|
id_agent: id_agent,
|
|
|
|
date_from: newdate,
|
|
|
|
time_from: from + ":00",
|
|
|
|
status: "-1",
|
2020-03-24 10:12:14 +01:00
|
|
|
group_rep: "1",
|
|
|
|
from_event_graph: 1,
|
|
|
|
id_server_meta: server_id
|
2019-12-10 15:29:35 +01:00
|
|
|
};
|
|
|
|
|
2019-01-30 12:27:18 +01:00
|
|
|
if (full_legend != "") {
|
2019-12-10 15:29:35 +01:00
|
|
|
if (newdate2 != undefined) {
|
|
|
|
url_filters.date_to = newdate2;
|
|
|
|
url_filters.time_to = to + ":00";
|
2019-01-30 12:27:18 +01:00
|
|
|
}
|
|
|
|
} else {
|
2019-12-10 15:29:35 +01:00
|
|
|
url_filters.date_to = newdate;
|
|
|
|
url_filters.time_to = to + ":00";
|
2019-01-30 12:27:18 +01:00
|
|
|
}
|
2019-12-10 15:29:35 +01:00
|
|
|
|
|
|
|
var url_filters_fb64 = btoa(JSON.stringify(url_filters));
|
|
|
|
|
|
|
|
window.location =
|
|
|
|
"index.php?sec=eventos&sec2=operation/events/events&fb64=" +
|
|
|
|
url_filters_fb64;
|
2019-01-30 12:27:18 +01:00
|
|
|
}
|
|
|
|
});
|
2016-05-26 08:57:33 +02:00
|
|
|
|
2019-01-30 12:27:18 +01:00
|
|
|
$("#" + graph_id).bind("mouseout", resetInteractivity);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Reset interactivity styles
|
|
|
|
function resetInteractivity() {
|
|
|
|
$("#extra_" + graph_id).hide();
|
|
|
|
}
|
|
|
|
|
|
|
|
// Format functions
|
2020-01-24 15:13:42 +01:00
|
|
|
function xFormatter(v) {
|
2020-03-26 12:29:38 +01:00
|
|
|
var ct = new Date();
|
|
|
|
var currentTime = ct.getTime();
|
|
|
|
|
|
|
|
var diffDates = (currentTime - 1000 * datelimit) / 1000;
|
|
|
|
|
2020-01-24 15:13:42 +01:00
|
|
|
var d = new Date(1000 * (v + datelimit));
|
2019-10-11 09:04:13 +02:00
|
|
|
var monthNames = [
|
|
|
|
"Jan",
|
|
|
|
"Feb",
|
|
|
|
"Mar",
|
|
|
|
"Apr",
|
|
|
|
"May",
|
|
|
|
"Jun",
|
|
|
|
"Jul",
|
|
|
|
"Aug",
|
|
|
|
"Sep",
|
|
|
|
"Oct",
|
|
|
|
"Nov",
|
|
|
|
"Dec"
|
|
|
|
];
|
|
|
|
|
2020-03-26 12:29:38 +01:00
|
|
|
var date_format = "";
|
|
|
|
if (diffDates > 86500) {
|
|
|
|
date_format =
|
|
|
|
(d.getDate() < 10 ? "0" : "") +
|
|
|
|
d.getDate() +
|
|
|
|
" " +
|
|
|
|
monthNames[d.getMonth()] +
|
|
|
|
"<br>" +
|
|
|
|
(d.getHours() < 10 ? "0" : "") +
|
|
|
|
d.getHours() +
|
|
|
|
":" +
|
|
|
|
(d.getMinutes() < 10 ? "0" : "") +
|
|
|
|
d.getMinutes();
|
|
|
|
} else {
|
|
|
|
date_format =
|
|
|
|
(d.getHours() < 10 ? "0" : "") +
|
|
|
|
d.getHours() +
|
|
|
|
":" +
|
|
|
|
(d.getMinutes() < 10 ? "0" : "") +
|
|
|
|
d.getMinutes();
|
|
|
|
}
|
2019-01-30 12:27:18 +01:00
|
|
|
return date_format;
|
|
|
|
}
|
|
|
|
}
|
2016-05-26 08:57:33 +02:00
|
|
|
|
2020-01-24 15:13:42 +01:00
|
|
|
// eslint-disable-next-line no-unused-vars
|
2019-01-30 12:27:18 +01:00
|
|
|
function pandoraFlotArea(
|
|
|
|
graph_id,
|
|
|
|
values,
|
|
|
|
legend,
|
|
|
|
series_type,
|
|
|
|
color,
|
|
|
|
date_array,
|
|
|
|
data_module_graph,
|
|
|
|
params,
|
|
|
|
events_array
|
|
|
|
) {
|
|
|
|
//diferents vars
|
|
|
|
var unit = params.unit ? params.unit : "";
|
|
|
|
var homeurl = params.homeurl;
|
|
|
|
var font_size = parseInt(params.font_size);
|
|
|
|
var font = params.font
|
|
|
|
.split("/")
|
|
|
|
.pop()
|
|
|
|
.split(".")
|
|
|
|
.shift();
|
|
|
|
var width = params.width;
|
|
|
|
var vconsole = params.vconsole;
|
|
|
|
var menu = params.menu;
|
|
|
|
var min_x = date_array["start_date"] * 1000;
|
|
|
|
var max_x = date_array["final_date"] * 1000;
|
|
|
|
var type = parseInt(params.stacked);
|
|
|
|
var show_legend = params.show_legend;
|
2022-05-18 17:17:31 +02:00
|
|
|
var image_threshold = params.image_threshold;
|
2020-03-26 12:29:38 +01:00
|
|
|
var short_data = params.short_data != "" ? params.short_data : 3;
|
2019-01-30 12:27:18 +01:00
|
|
|
var grid_color = params.grid_color;
|
|
|
|
var background_color = params.backgroundColor;
|
|
|
|
var legend_color = params.legend_color;
|
|
|
|
var update_legend = {};
|
|
|
|
var force_integer = 0;
|
2019-12-05 17:41:44 +01:00
|
|
|
var divisor = params.divisor;
|
2020-10-05 17:03:30 +02:00
|
|
|
var maximum_y_axis = params.maximum_y_axis;
|
2021-08-03 15:46:01 +02:00
|
|
|
var basic_chart = params.basic_chart;
|
2019-12-05 17:41:44 +01:00
|
|
|
|
|
|
|
if (typeof divisor === "undefined") {
|
|
|
|
divisor = 1000;
|
|
|
|
}
|
2019-01-30 12:27:18 +01:00
|
|
|
|
|
|
|
if (typeof type === "undefined" || type == "") {
|
|
|
|
type = params.type_graph;
|
|
|
|
}
|
|
|
|
|
|
|
|
//for threshold
|
|
|
|
var threshold = true;
|
|
|
|
var thresholded = false;
|
|
|
|
var yellow_threshold = parseFloat(data_module_graph.w_min);
|
|
|
|
var red_threshold = parseFloat(data_module_graph.c_min);
|
|
|
|
var yellow_up = parseFloat(data_module_graph.w_max);
|
|
|
|
var red_up = parseFloat(data_module_graph.c_max);
|
|
|
|
var yellow_inverse = parseInt(data_module_graph.w_inv);
|
|
|
|
var red_inverse = parseInt(data_module_graph.c_inv);
|
|
|
|
var markins_graph = true;
|
|
|
|
|
|
|
|
// If threshold and up are the same, that critical or warning is disabled
|
|
|
|
if (yellow_threshold == yellow_up) {
|
|
|
|
yellow_inverse = false;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (red_threshold == red_up) {
|
|
|
|
red_inverse = false;
|
|
|
|
}
|
|
|
|
|
|
|
|
//Array with points to be painted
|
|
|
|
var threshold_data = new Array();
|
|
|
|
//Array with some interesting points
|
|
|
|
var extremes = new Array();
|
|
|
|
|
|
|
|
var yellow_only_min = yellow_up == 0 && yellow_threshold != 0;
|
|
|
|
var red_only_min = red_up == 0 && red_threshold != 0;
|
|
|
|
|
|
|
|
//color
|
|
|
|
var warning = "yellow";
|
|
|
|
var critical = "red";
|
|
|
|
|
|
|
|
if (threshold) {
|
|
|
|
// Warning interval. Change extremes depends on critical interval
|
|
|
|
if (yellow_inverse && red_inverse) {
|
|
|
|
if (red_only_min && yellow_only_min) {
|
|
|
|
// C: |-------- |
|
|
|
|
// W: |········==== |
|
|
|
|
if (yellow_threshold > red_threshold) {
|
|
|
|
threshold_data.push({
|
|
|
|
id: "warning_normal_fdown",
|
|
|
|
data: [[max_x, red_threshold]],
|
|
|
|
label: null,
|
|
|
|
color: warning,
|
|
|
|
bars: {
|
|
|
|
show: true,
|
|
|
|
align: "left",
|
|
|
|
barWidth: yellow_threshold - red_threshold,
|
|
|
|
lineWidth: 0,
|
|
|
|
horizontal: true,
|
|
|
|
fillColor: {
|
|
|
|
colors: [
|
|
|
|
{
|
|
|
|
opacity: 0.1
|
|
|
|
},
|
|
|
|
{
|
|
|
|
opacity: 0.1
|
|
|
|
}
|
|
|
|
]
|
|
|
|
}
|
|
|
|
},
|
|
|
|
highlightColor: "rgba(254, 255, 198, 0)"
|
|
|
|
});
|
|
|
|
|
|
|
|
extremes["warning_normal_fdown_1"] = red_threshold;
|
|
|
|
extremes["warning_normal_fdown_2"] = yellow_threshold;
|
|
|
|
}
|
|
|
|
} else if (!red_only_min && yellow_only_min) {
|
|
|
|
// C: |-------- ------|
|
|
|
|
// W: |········===· |
|
|
|
|
if (yellow_threshold > red_up) {
|
|
|
|
yellow_threshold = red_up;
|
|
|
|
}
|
|
|
|
if (yellow_threshold > red_threshold) {
|
|
|
|
threshold_data.push({
|
|
|
|
id: "warning_normal_fdown",
|
|
|
|
data: [[max_x, red_threshold]],
|
|
|
|
label: null,
|
|
|
|
color: warning,
|
|
|
|
bars: {
|
|
|
|
show: true,
|
|
|
|
align: "left",
|
|
|
|
barWidth: yellow_threshold - red_threshold,
|
|
|
|
lineWidth: 0,
|
|
|
|
horizontal: true,
|
|
|
|
fillColor: { colors: [{ opacity: 0.1 }, { opacity: 0.1 }] }
|
|
|
|
},
|
|
|
|
highlightColor: "rgba(254, 255, 198, 0)"
|
|
|
|
});
|
|
|
|
extremes["warning_normal_fdown_1"] = red_threshold;
|
|
|
|
extremes["warning_normal_fdown_2"] = yellow_threshold;
|
|
|
|
}
|
|
|
|
} else if (red_only_min && !yellow_only_min) {
|
|
|
|
// C: |------- |
|
|
|
|
// W: |·······==== ===|
|
|
|
|
if (red_threshold < yellow_threshold) {
|
|
|
|
threshold_data.push({
|
|
|
|
id: "warning_normal_fdown",
|
|
|
|
data: [[max_x, red_threshold]],
|
|
|
|
label: null,
|
|
|
|
color: warning,
|
|
|
|
bars: {
|
|
|
|
show: true,
|
|
|
|
align: "left",
|
|
|
|
barWidth: yellow_threshold - red_threshold,
|
|
|
|
lineWidth: 0,
|
|
|
|
horizontal: true,
|
|
|
|
fillColor: { colors: [{ opacity: 0.1 }, { opacity: 0.1 }] }
|
|
|
|
},
|
|
|
|
highlightColor: "rgba(254, 255, 198, 0)"
|
|
|
|
});
|
|
|
|
extremes["warning_normal_fdown_1"] = red_threshold;
|
|
|
|
extremes["warning_normal_fdown_2"] = yellow_threshold;
|
|
|
|
}
|
2018-10-16 15:32:31 +02:00
|
|
|
|
2019-01-30 12:27:18 +01:00
|
|
|
if (yellow_up < red_threshold) {
|
|
|
|
yellow_up = red_threshold;
|
|
|
|
}
|
|
|
|
threshold_data.push({
|
|
|
|
// barWidth will be correct on draw time
|
|
|
|
id: "warning_up",
|
|
|
|
data: [[max_x, yellow_up]],
|
|
|
|
label: null,
|
|
|
|
color: warning,
|
|
|
|
bars: {
|
|
|
|
show: true,
|
|
|
|
align: "left",
|
|
|
|
barWidth: 1,
|
|
|
|
lineWidth: 0,
|
|
|
|
horizontal: true,
|
|
|
|
fillColor: { colors: [{ opacity: 0.1 }, { opacity: 0.1 }] }
|
|
|
|
},
|
|
|
|
highlightColor: "rgba(254, 255, 198, 0)"
|
|
|
|
});
|
|
|
|
extremes["warning_up"] = yellow_up;
|
|
|
|
} else {
|
|
|
|
if (yellow_threshold > red_threshold) {
|
|
|
|
// C: |-------- ------|
|
|
|
|
// W: |········===· ···|
|
|
|
|
if (yellow_threshold > red_up) {
|
|
|
|
yellow_threshold = red_up;
|
|
|
|
}
|
|
|
|
threshold_data.push({
|
|
|
|
id: "warning_normal_fdown",
|
|
|
|
data: [[max_x, red_threshold]],
|
|
|
|
label: null,
|
|
|
|
color: warning,
|
|
|
|
bars: {
|
|
|
|
show: true,
|
|
|
|
align: "left",
|
|
|
|
barWidth: yellow_threshold - red_threshold,
|
|
|
|
lineWidth: 0,
|
|
|
|
horizontal: true,
|
|
|
|
fillColor: { colors: [{ opacity: 0.1 }, { opacity: 0.1 }] }
|
|
|
|
},
|
|
|
|
highlightColor: "rgba(254, 255, 198, 0)"
|
|
|
|
});
|
|
|
|
extremes["warning_normal_fdown_1"] = red_threshold;
|
|
|
|
extremes["warning_normal_fdown_2"] = yellow_threshold;
|
|
|
|
}
|
|
|
|
if (yellow_up < red_up) {
|
|
|
|
// C: |-------- ---|
|
|
|
|
// W: |····· ·======···|
|
|
|
|
if (yellow_up < red_threshold) {
|
|
|
|
yellow_up = red_up;
|
|
|
|
}
|
|
|
|
threshold_data.push({
|
|
|
|
id: "warning_normal_fup",
|
|
|
|
data: [[max_x, yellow_up]],
|
|
|
|
label: null,
|
|
|
|
color: warning,
|
|
|
|
bars: {
|
|
|
|
show: true,
|
|
|
|
align: "left",
|
|
|
|
barWidth: red_up - yellow_up,
|
|
|
|
lineWidth: 0,
|
|
|
|
horizontal: true,
|
|
|
|
fillColor: { colors: [{ opacity: 0.1 }, { opacity: 0.1 }] }
|
|
|
|
},
|
|
|
|
highlightColor: "rgba(254, 255, 198, 0)"
|
|
|
|
});
|
|
|
|
extremes["warning_normal_fup_1"] = red_up;
|
|
|
|
extremes["warning_normal_fup_2"] = yellow_up;
|
|
|
|
}
|
|
|
|
// If warning is under critical completely do not paint anything yellow
|
|
|
|
// C: |-------- -----|
|
|
|
|
// W: |···· ···|
|
|
|
|
}
|
|
|
|
} else if (yellow_inverse && !red_inverse) {
|
|
|
|
if (red_only_min && yellow_only_min) {
|
|
|
|
// C: | -----|
|
|
|
|
// W: |============··· |
|
|
|
|
if (yellow_threshold > red_threshold) {
|
|
|
|
yellow_threshold = red_threshold;
|
|
|
|
}
|
|
|
|
threshold_data.push({
|
|
|
|
// barWidth will be correct on draw time
|
|
|
|
id: "warning_down",
|
|
|
|
data: [[max_x, yellow_threshold]],
|
|
|
|
label: null,
|
|
|
|
color: warning,
|
|
|
|
bars: {
|
|
|
|
show: true,
|
|
|
|
align: "left",
|
|
|
|
barWidth: 1,
|
|
|
|
lineWidth: 0,
|
|
|
|
horizontal: true,
|
|
|
|
fillColor: { colors: [{ opacity: 0.1 }, { opacity: 0.1 }] }
|
|
|
|
},
|
|
|
|
highlightColor: "rgba(254, 255, 198, 0)"
|
|
|
|
});
|
|
|
|
extremes["warning_down"] = yellow_threshold;
|
|
|
|
} else if (!red_only_min && yellow_only_min) {
|
|
|
|
// C: | ---- |
|
|
|
|
// W: |======····=== |
|
|
|
|
|
|
|
|
if (yellow_threshold > red_up) {
|
|
|
|
threshold_data.push({
|
|
|
|
id: "warning_normal_fdown",
|
|
|
|
data: [[max_x, red_up]],
|
|
|
|
label: null,
|
|
|
|
color: warning,
|
|
|
|
bars: {
|
|
|
|
show: true,
|
|
|
|
align: "left",
|
|
|
|
barWidth: yellow_threshold - red_up,
|
|
|
|
lineWidth: 0,
|
|
|
|
horizontal: true,
|
|
|
|
fillColor: { colors: [{ opacity: 0.1 }, { opacity: 0.1 }] }
|
|
|
|
},
|
|
|
|
highlightColor: "rgba(254, 255, 198, 0)"
|
|
|
|
});
|
|
|
|
extremes["warning_normal_fdown_1"] = red_up;
|
|
|
|
extremes["warning_normal_fdown_2"] = yellow_threshold;
|
|
|
|
}
|
2016-05-26 08:57:33 +02:00
|
|
|
|
2019-01-30 12:27:18 +01:00
|
|
|
if (yellow_threshold > red_threshold) {
|
|
|
|
yellow_threshold = red_threshold;
|
|
|
|
}
|
|
|
|
threshold_data.push({
|
|
|
|
// barWidth will be correct on draw time
|
|
|
|
id: "warning_down",
|
|
|
|
data: [[max_x, yellow_threshold]],
|
|
|
|
label: null,
|
|
|
|
color: warning,
|
|
|
|
bars: {
|
|
|
|
show: true,
|
|
|
|
align: "left",
|
|
|
|
barWidth: 1,
|
|
|
|
lineWidth: 0,
|
|
|
|
horizontal: true,
|
|
|
|
fillColor: { colors: [{ opacity: 0.1 }, { opacity: 0.1 }] }
|
|
|
|
},
|
|
|
|
highlightColor: "rgba(254, 255, 198, 0)"
|
|
|
|
});
|
|
|
|
extremes["warning_down"] = yellow_threshold;
|
|
|
|
} else if (red_only_min && !yellow_only_min) {
|
|
|
|
if (yellow_threshold < red_threshold) {
|
|
|
|
// C: | -----|
|
|
|
|
// W: |======= ===·····|
|
|
|
|
threshold_data.push({
|
|
|
|
// barWidth will be correct on draw time
|
|
|
|
id: "warning_down",
|
|
|
|
data: [[max_x, yellow_threshold]],
|
|
|
|
label: null,
|
|
|
|
color: warning,
|
|
|
|
bars: {
|
|
|
|
show: true,
|
|
|
|
align: "left",
|
|
|
|
barWidth: 1,
|
|
|
|
lineWidth: 0,
|
|
|
|
horizontal: true,
|
|
|
|
fillColor: { colors: [{ opacity: 0.1 }, { opacity: 0.1 }] }
|
|
|
|
},
|
|
|
|
highlightColor: "rgba(254, 255, 198, 0)"
|
|
|
|
});
|
|
|
|
extremes["warning_down"] = yellow_threshold;
|
|
|
|
|
|
|
|
if (red_threshold > yellow_up) {
|
|
|
|
threshold_data.push({
|
|
|
|
id: "warning_normal_fup",
|
|
|
|
data: [[max_x, yellow_up]],
|
|
|
|
label: null,
|
|
|
|
color: warning,
|
|
|
|
bars: {
|
|
|
|
show: true,
|
|
|
|
align: "left",
|
|
|
|
barWidth: red_threshold - yellow_up,
|
|
|
|
lineWidth: 0,
|
|
|
|
horizontal: true,
|
|
|
|
fillColor: { colors: [{ opacity: 0.1 }, { opacity: 0.1 }] }
|
|
|
|
},
|
|
|
|
highlightColor: "rgba(254, 255, 198, 0)"
|
|
|
|
});
|
|
|
|
extremes["warning_normal_fup_1"] = yellow_up;
|
|
|
|
extremes["warning_normal_fup_2"] = red_threshold;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
// C: | ------------|
|
|
|
|
// W: |=====·· ········|
|
|
|
|
threshold_data.push({
|
|
|
|
// barWidth will be correct on draw time
|
|
|
|
id: "warning_down",
|
|
|
|
data: [[max_x, red_threshold]],
|
|
|
|
label: null,
|
|
|
|
color: warning,
|
|
|
|
bars: {
|
|
|
|
show: true,
|
|
|
|
align: "left",
|
|
|
|
barWidth: 1,
|
|
|
|
lineWidth: 0,
|
|
|
|
horizontal: true,
|
|
|
|
fillColor: { colors: [{ opacity: 0.1 }, { opacity: 0.1 }] }
|
|
|
|
},
|
|
|
|
highlightColor: "rgba(254, 255, 198, 0)"
|
|
|
|
});
|
|
|
|
extremes["warning_down"] = red_threshold;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
if (yellow_threshold > red_up) {
|
|
|
|
// C: | ----- |
|
|
|
|
// W: |====·····=== ===|
|
|
|
|
threshold_data.push({
|
|
|
|
// barWidth will be correct on draw time
|
|
|
|
id: "warning_down",
|
|
|
|
data: [[max_x, red_threshold]],
|
|
|
|
label: null,
|
|
|
|
color: warning,
|
|
|
|
bars: {
|
|
|
|
show: true,
|
|
|
|
align: "left",
|
|
|
|
barWidth: 1,
|
|
|
|
lineWidth: 0,
|
|
|
|
horizontal: true,
|
|
|
|
fillColor: { colors: [{ opacity: 0.1 }, { opacity: 0.1 }] }
|
|
|
|
},
|
|
|
|
highlightColor: "rgba(254, 255, 198, 0)"
|
|
|
|
});
|
|
|
|
extremes["warning_down"] = red_threshold;
|
|
|
|
|
|
|
|
threshold_data.push({
|
|
|
|
id: "warning_normal_fdown",
|
|
|
|
data: [[max_x, red_up]],
|
|
|
|
label: null,
|
|
|
|
color: warning,
|
|
|
|
bars: {
|
|
|
|
show: true,
|
|
|
|
align: "left",
|
|
|
|
barWidth: yellow_threshold - red_up,
|
|
|
|
lineWidth: 0,
|
|
|
|
horizontal: true,
|
|
|
|
fillColor: { colors: [{ opacity: 0.1 }, { opacity: 0.1 }] }
|
|
|
|
},
|
|
|
|
highlightColor: "rgba(254, 255, 198, 0)"
|
|
|
|
});
|
|
|
|
extremes["warning_normal_fdown_1"] = red_up;
|
|
|
|
extremes["warning_normal_fdown_2"] = yellow_threshold;
|
|
|
|
|
|
|
|
threshold_data.push({
|
|
|
|
// barWidth will be correct on draw time
|
|
|
|
id: "warning_up",
|
|
|
|
data: [[max_x, yellow_up]],
|
|
|
|
label: null,
|
|
|
|
color: warning,
|
|
|
|
bars: {
|
|
|
|
show: true,
|
|
|
|
align: "left",
|
|
|
|
barWidth: 1,
|
|
|
|
lineWidth: 0,
|
|
|
|
horizontal: true,
|
|
|
|
fillColor: { colors: [{ opacity: 0.1 }, { opacity: 0.1 }] }
|
|
|
|
},
|
|
|
|
highlightColor: "rgba(254, 255, 198, 0)"
|
|
|
|
});
|
|
|
|
extremes["warning_up"] = yellow_up;
|
|
|
|
} else if (red_threshold > yellow_up) {
|
|
|
|
// C: | ----- |
|
|
|
|
// W: |=== ===·····==|
|
|
|
|
threshold_data.push({
|
|
|
|
// barWidth will be correct on draw time
|
|
|
|
id: "warning_down",
|
|
|
|
data: [[max_x, yellow_threshold]],
|
|
|
|
label: null,
|
|
|
|
color: warning,
|
|
|
|
bars: {
|
|
|
|
show: true,
|
|
|
|
align: "left",
|
|
|
|
barWidth: 1,
|
|
|
|
lineWidth: 0,
|
|
|
|
horizontal: true,
|
|
|
|
fillColor: { colors: [{ opacity: 0.1 }, { opacity: 0.1 }] }
|
|
|
|
},
|
|
|
|
highlightColor: "rgba(254, 255, 198, 0)"
|
|
|
|
});
|
|
|
|
extremes["warning_down"] = yellow_threshold;
|
|
|
|
|
|
|
|
threshold_data.push({
|
|
|
|
id: "warning_normal_fup",
|
|
|
|
data: [[max_x, yellow_up]],
|
|
|
|
label: null,
|
|
|
|
color: warning,
|
|
|
|
bars: {
|
|
|
|
show: true,
|
|
|
|
align: "left",
|
|
|
|
barWidth: red_threshold - yellow_up,
|
|
|
|
lineWidth: 0,
|
|
|
|
horizontal: true,
|
|
|
|
fillColor: { colors: [{ opacity: 0.1 }, { opacity: 0.1 }] }
|
|
|
|
},
|
|
|
|
highlightColor: "rgba(254, 255, 198, 0)"
|
|
|
|
});
|
|
|
|
extremes["warning_normal_fup_1"] = yellow_up;
|
|
|
|
extremes["warning_normal_fup_2"] = red_threshold;
|
|
|
|
|
|
|
|
threshold_data.push({
|
|
|
|
// barWidth will be correct on draw time
|
|
|
|
id: "warning_up",
|
|
|
|
data: [[max_x, red_up]],
|
|
|
|
label: null,
|
|
|
|
color: warning,
|
|
|
|
bars: {
|
|
|
|
show: true,
|
|
|
|
align: "left",
|
|
|
|
barWidth: 1,
|
|
|
|
lineWidth: 0,
|
|
|
|
horizontal: true,
|
|
|
|
fillColor: { colors: [{ opacity: 0.1 }, { opacity: 0.1 }] }
|
|
|
|
},
|
|
|
|
highlightColor: "rgba(254, 255, 198, 0)"
|
|
|
|
});
|
|
|
|
extremes["warning_up"] = red_up;
|
|
|
|
} else {
|
|
|
|
// C: | -------- |
|
|
|
|
// W: |==· ···=======|
|
|
|
|
if (yellow_threshold > red_threshold) {
|
|
|
|
yellow_threshold = red_threshold;
|
|
|
|
}
|
|
|
|
if (yellow_up < red_up) {
|
|
|
|
yellow_up = red_up;
|
|
|
|
}
|
|
|
|
|
|
|
|
threshold_data.push({
|
|
|
|
// barWidth will be correct on draw time
|
|
|
|
id: "warning_down",
|
|
|
|
data: [[max_x, yellow_threshold]],
|
|
|
|
label: null,
|
|
|
|
color: warning,
|
|
|
|
bars: {
|
|
|
|
show: true,
|
|
|
|
align: "left",
|
|
|
|
barWidth: 1,
|
|
|
|
lineWidth: 0,
|
|
|
|
horizontal: true,
|
|
|
|
fillColor: { colors: [{ opacity: 0.1 }, { opacity: 0.1 }] }
|
|
|
|
},
|
|
|
|
highlightColor: "rgba(254, 255, 198, 0)"
|
|
|
|
});
|
|
|
|
extremes["warning_down"] = yellow_threshold;
|
|
|
|
|
|
|
|
threshold_data.push({
|
|
|
|
// barWidth will be correct on draw time
|
|
|
|
id: "warning_up",
|
|
|
|
data: [[max_x, yellow_up]],
|
|
|
|
label: null,
|
|
|
|
color: warning,
|
|
|
|
bars: {
|
|
|
|
show: true,
|
|
|
|
align: "left",
|
|
|
|
barWidth: 1,
|
|
|
|
lineWidth: 0,
|
|
|
|
horizontal: true,
|
|
|
|
fillColor: { colors: [{ opacity: 0.1 }, { opacity: 0.1 }] }
|
|
|
|
},
|
|
|
|
highlightColor: "rgba(254, 255, 198, 0)"
|
|
|
|
});
|
|
|
|
extremes["warning_up"] = yellow_up;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} else if (!yellow_inverse && red_inverse) {
|
|
|
|
if (yellow_only_min && red_only_min) {
|
|
|
|
// C: |----- |
|
|
|
|
// W: | ··============|
|
|
|
|
if (yellow_threshold < red_threshold) {
|
|
|
|
yellow_threshold = red_threshold;
|
|
|
|
}
|
|
|
|
threshold_data.push({
|
|
|
|
// barWidth will be correct on draw time
|
|
|
|
id: "warning_up",
|
|
|
|
data: [[max_x, yellow_threshold]],
|
|
|
|
label: null,
|
|
|
|
color: warning,
|
|
|
|
bars: {
|
|
|
|
show: true,
|
|
|
|
align: "left",
|
|
|
|
barWidth: 1,
|
|
|
|
lineWidth: 0,
|
|
|
|
horizontal: true,
|
|
|
|
fillColor: { colors: [{ opacity: 0.1 }, { opacity: 0.1 }] }
|
|
|
|
},
|
|
|
|
highlightColor: "rgba(254, 255, 198, 0)"
|
|
|
|
});
|
|
|
|
extremes["warning_up"] = yellow_threshold;
|
|
|
|
} else if (!yellow_only_min && red_only_min) {
|
|
|
|
// C: |----- |
|
|
|
|
// W: | ··======== |
|
|
|
|
if (yellow_threshold < red_threshold) {
|
|
|
|
yellow_threshold = red_threshold;
|
|
|
|
}
|
|
|
|
if (yellow_up > red_threshold) {
|
|
|
|
threshold_data.push({
|
|
|
|
id: "warning_normal",
|
|
|
|
data: [[max_x, yellow_threshold]],
|
|
|
|
label: null,
|
|
|
|
color: warning,
|
|
|
|
bars: {
|
|
|
|
show: true,
|
|
|
|
align: "left",
|
|
|
|
barWidth: yellow_up - yellow_threshold,
|
|
|
|
lineWidth: 0,
|
|
|
|
horizontal: true,
|
|
|
|
fillColor: { colors: [{ opacity: 0.1 }, { opacity: 0.1 }] }
|
|
|
|
},
|
|
|
|
highlightColor: "rgba(254, 255, 198, 0)"
|
|
|
|
});
|
|
|
|
extremes["warning_normal_1"] = yellow_threshold;
|
|
|
|
extremes["warning_normal_2"] = yellow_up;
|
|
|
|
}
|
|
|
|
} else if (yellow_only_min && !red_only_min) {
|
|
|
|
// C: |----- ------|
|
|
|
|
// W: | ··======······|
|
|
|
|
if (yellow_threshold < red_threshold) {
|
|
|
|
yellow_threshold = red_threshold;
|
|
|
|
}
|
|
|
|
if (yellow_threshold < red_up) {
|
|
|
|
threshold_data.push({
|
|
|
|
id: "warning_normal",
|
|
|
|
data: [[max_x, yellow_threshold]],
|
|
|
|
label: null,
|
|
|
|
color: warning,
|
|
|
|
bars: {
|
|
|
|
show: true,
|
|
|
|
align: "left",
|
|
|
|
barWidth: red_up - yellow_threshold,
|
|
|
|
lineWidth: 0,
|
|
|
|
horizontal: true,
|
|
|
|
fillColor: { colors: [{ opacity: 0.1 }, { opacity: 0.1 }] }
|
|
|
|
},
|
|
|
|
highlightColor: "rgba(254, 255, 198, 0)"
|
|
|
|
});
|
|
|
|
extremes["warning_normal_1"] = yellow_threshold;
|
|
|
|
extremes["warning_normal_2"] = red_up;
|
|
|
|
}
|
|
|
|
// If warning is under critical completely do not paint anything yellow
|
|
|
|
// C: |-------- -----|
|
|
|
|
// W: | ···|
|
|
|
|
} else {
|
|
|
|
if (red_up > yellow_threshold && red_threshold < yellow_up) {
|
|
|
|
// C: |----- ------|
|
|
|
|
// W: | ··======· |
|
|
|
|
if (yellow_threshold < red_threshold) {
|
|
|
|
yellow_threshold = red_threshold;
|
|
|
|
}
|
|
|
|
if (yellow_up > red_up) {
|
|
|
|
yellow_up = red_up;
|
|
|
|
}
|
|
|
|
|
|
|
|
threshold_data.push({
|
|
|
|
id: "warning_normal",
|
|
|
|
data: [[max_x, yellow_threshold]],
|
|
|
|
label: null,
|
|
|
|
color: warning,
|
|
|
|
bars: {
|
|
|
|
show: true,
|
|
|
|
align: "left",
|
|
|
|
barWidth: yellow_up - yellow_threshold,
|
|
|
|
lineWidth: 0,
|
|
|
|
horizontal: true,
|
|
|
|
fillColor: { colors: [{ opacity: 0.1 }, { opacity: 0.1 }] }
|
|
|
|
},
|
|
|
|
highlightColor: "rgba(254, 255, 198, 0)"
|
|
|
|
});
|
|
|
|
extremes["warning_normal_1"] = yellow_threshold;
|
|
|
|
extremes["warning_normal_2"] = yellow_up;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
// If warning is under critical completely do not paint anything yellow
|
|
|
|
// C: |-------- -----| or // C: |-------- -----|
|
|
|
|
// W: | ···· | // W: | ·· |
|
|
|
|
else {
|
|
|
|
if (red_only_min && yellow_only_min) {
|
|
|
|
if (yellow_threshold < red_threshold) {
|
|
|
|
// C: | ---------|
|
|
|
|
// W: | =====·········|
|
|
|
|
threshold_data.push({
|
|
|
|
id: "warning_normal",
|
|
|
|
data: [[max_x, yellow_threshold]],
|
|
|
|
label: null,
|
|
|
|
color: warning,
|
|
|
|
bars: {
|
|
|
|
show: true,
|
|
|
|
align: "left",
|
|
|
|
barWidth: red_threshold - yellow_threshold,
|
|
|
|
lineWidth: 0,
|
|
|
|
horizontal: true,
|
|
|
|
fillColor: { colors: [{ opacity: 0.1 }, { opacity: 0.1 }] }
|
|
|
|
},
|
|
|
|
highlightColor: "rgba(254, 255, 198, 0)"
|
|
|
|
});
|
|
|
|
extremes["warning_normal_1"] = yellow_threshold;
|
|
|
|
extremes["warning_normal_2"] = red_threshold;
|
|
|
|
}
|
|
|
|
} else if (red_only_min && !yellow_only_min) {
|
|
|
|
// C: | ---------|
|
|
|
|
// W: | =====··· |
|
|
|
|
if (yellow_up > red_threshold) {
|
|
|
|
yellow_up = red_threshold;
|
|
|
|
}
|
|
|
|
if (yellow_threshold < red_threshold) {
|
|
|
|
threshold_data.push({
|
|
|
|
id: "warning_normal",
|
|
|
|
data: [[max_x, yellow_threshold]],
|
|
|
|
label: null,
|
|
|
|
color: warning,
|
|
|
|
bars: {
|
|
|
|
show: true,
|
|
|
|
align: "left",
|
|
|
|
barWidth: yellow_up - yellow_threshold,
|
|
|
|
lineWidth: 0,
|
|
|
|
horizontal: true,
|
|
|
|
fillColor: { colors: [{ opacity: 0.1 }, { opacity: 0.1 }] }
|
|
|
|
},
|
|
|
|
highlightColor: "rgba(254, 255, 198, 0)"
|
|
|
|
});
|
|
|
|
extremes["warning_normal_1"] = yellow_threshold;
|
|
|
|
extremes["warning_normal_2"] = yellow_up;
|
|
|
|
}
|
|
|
|
} else if (!red_only_min && yellow_only_min) {
|
|
|
|
// C: | ------- |
|
|
|
|
// W: | ==·······=====|
|
|
|
|
if (yellow_threshold < red_threshold) {
|
|
|
|
threshold_data.push({
|
|
|
|
id: "warning_normal_fdown",
|
|
|
|
data: [[max_x, yellow_threshold]],
|
|
|
|
label: null,
|
|
|
|
color: warning,
|
|
|
|
bars: {
|
|
|
|
show: true,
|
|
|
|
align: "left",
|
|
|
|
barWidth: red_threshold - yellow_threshold,
|
|
|
|
lineWidth: 0,
|
|
|
|
horizontal: true,
|
|
|
|
fillColor: { colors: [{ opacity: 0.1 }, { opacity: 0.1 }] }
|
|
|
|
},
|
|
|
|
highlightColor: "rgba(254, 255, 198, 0)"
|
|
|
|
});
|
|
|
|
extremes["warning_normal_fdown_1"] = yellow_threshold;
|
|
|
|
extremes["warning_normal_fdown_2"] = red_threshold;
|
|
|
|
}
|
2016-08-19 12:46:27 +02:00
|
|
|
|
2019-01-30 12:27:18 +01:00
|
|
|
if (yellow_threshold < red_up) {
|
|
|
|
yellow_threshold = red_up;
|
|
|
|
}
|
2016-05-26 08:57:33 +02:00
|
|
|
|
2019-01-30 12:27:18 +01:00
|
|
|
threshold_data.push({
|
|
|
|
// barWidth will be correct on draw time
|
|
|
|
id: "warning_up",
|
|
|
|
data: [[max_x, yellow_threshold]],
|
|
|
|
label: null,
|
|
|
|
color: warning,
|
|
|
|
bars: {
|
|
|
|
show: true,
|
|
|
|
align: "left",
|
|
|
|
barWidth: 1,
|
|
|
|
lineWidth: 0,
|
|
|
|
horizontal: true,
|
|
|
|
fillColor: { colors: [{ opacity: 0.1 }, { opacity: 0.1 }] }
|
|
|
|
},
|
|
|
|
highlightColor: "rgba(254, 255, 198, 0)"
|
|
|
|
});
|
|
|
|
extremes["warning_up"] = yellow_threshold;
|
|
|
|
} else {
|
|
|
|
if (red_threshold > yellow_threshold && red_up < yellow_up) {
|
|
|
|
// C: | ------ |
|
|
|
|
// W: | ==······==== |
|
|
|
|
threshold_data.push({
|
|
|
|
id: "warning_normal_fdown",
|
|
|
|
data: [[max_x, yellow_threshold]],
|
|
|
|
label: null,
|
|
|
|
color: warning,
|
|
|
|
bars: {
|
|
|
|
show: true,
|
|
|
|
align: "left",
|
|
|
|
barWidth: red_threshold - yellow_threshold,
|
|
|
|
lineWidth: 0,
|
|
|
|
horizontal: true,
|
|
|
|
fillColor: { colors: [{ opacity: 0.1 }, { opacity: 0.1 }] }
|
|
|
|
},
|
|
|
|
highlightColor: "rgba(254, 255, 198, 0)"
|
|
|
|
});
|
|
|
|
extremes["warning_normal_fdown_1"] = yellow_threshold;
|
|
|
|
extremes["warning_normal_fdown_2"] = red_threshold;
|
|
|
|
|
|
|
|
threshold_data.push({
|
|
|
|
id: "warning_normal_fup",
|
|
|
|
data: [[max_x, red_up]],
|
|
|
|
label: null,
|
|
|
|
color: warning,
|
|
|
|
bars: {
|
|
|
|
show: true,
|
|
|
|
align: "left",
|
|
|
|
barWidth: yellow_up - red_up,
|
|
|
|
lineWidth: 0,
|
|
|
|
horizontal: true,
|
|
|
|
fillColor: { colors: [{ opacity: 0.1 }, { opacity: 0.1 }] }
|
|
|
|
},
|
|
|
|
highlightColor: "rgba(254, 255, 198, 0)"
|
|
|
|
});
|
|
|
|
extremes["warning_normal_fup_1"] = red_up;
|
|
|
|
extremes["warning_normal_fup_2"] = yellow_up;
|
|
|
|
} else if (red_threshold < yellow_threshold && red_up > yellow_up) {
|
|
|
|
// If warning is under critical completely do not paint anything yellow
|
|
|
|
// C: | -------- |
|
|
|
|
// W: | ···· |
|
|
|
|
} else {
|
|
|
|
// C: | -------- | or // C: | ------ |
|
|
|
|
// W: | ==·· | // W: | ···==== |
|
|
|
|
if (yellow_up > red_threshold && yellow_up < red_up) {
|
|
|
|
yellow_up = red_threshold;
|
|
|
|
}
|
|
|
|
if (yellow_threshold < red_up && yellow_threshold > red_threshold) {
|
|
|
|
yellow_threshold = red_up;
|
|
|
|
}
|
|
|
|
threshold_data.push({
|
|
|
|
id: "warning_normal",
|
|
|
|
data: [[max_x, yellow_threshold]],
|
|
|
|
label: null,
|
|
|
|
color: warning,
|
|
|
|
bars: {
|
|
|
|
show: true,
|
|
|
|
align: "left",
|
|
|
|
barWidth: yellow_up - yellow_threshold,
|
|
|
|
lineWidth: 0,
|
|
|
|
horizontal: true,
|
|
|
|
fillColor: { colors: [{ opacity: 0.1 }, { opacity: 0.1 }] }
|
|
|
|
},
|
|
|
|
highlightColor: "rgba(254, 255, 198, 0)"
|
|
|
|
});
|
|
|
|
extremes["warning_normal_1"] = yellow_threshold;
|
|
|
|
extremes["warning_normal_2"] = yellow_up;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2018-05-10 08:43:09 +02:00
|
|
|
|
2019-01-30 12:27:18 +01:00
|
|
|
// Critical interval
|
|
|
|
if (red_inverse) {
|
|
|
|
if (!red_only_min) {
|
|
|
|
threshold_data.push({
|
|
|
|
// barWidth will be correct on draw time
|
|
|
|
id: "critical_up",
|
|
|
|
data: [[max_x, red_up]],
|
|
|
|
label: null,
|
|
|
|
color: critical,
|
|
|
|
bars: {
|
|
|
|
show: true,
|
|
|
|
align: "left",
|
|
|
|
barWidth: 1,
|
|
|
|
lineWidth: 0,
|
|
|
|
horizontal: true,
|
|
|
|
fillColor: { colors: [{ opacity: 0.1 }, { opacity: 0.1 }] }
|
|
|
|
},
|
|
|
|
highlightColor: "rgba(254, 236, 234, 0)"
|
|
|
|
});
|
|
|
|
extremes["critical_normal_1"] = red_threshold;
|
|
|
|
extremes["critical_normal_2"] = red_up;
|
|
|
|
}
|
|
|
|
threshold_data.push({
|
|
|
|
// barWidth will be correct on draw time
|
|
|
|
id: "critical_down",
|
|
|
|
data: [[max_x, red_threshold]],
|
|
|
|
label: null,
|
|
|
|
color: critical,
|
|
|
|
bars: {
|
|
|
|
show: true,
|
|
|
|
align: "left",
|
|
|
|
barWidth: 1,
|
|
|
|
lineWidth: 0,
|
|
|
|
horizontal: true,
|
|
|
|
fillColor: { colors: [{ opacity: 0.1 }, { opacity: 0.1 }] }
|
|
|
|
},
|
|
|
|
highlightColor: "rgba(254, 236, 234, 0)"
|
|
|
|
});
|
|
|
|
extremes["critical_normal_3"] = red_threshold;
|
|
|
|
extremes["critical_normal_4"] = red_threshold;
|
|
|
|
} else {
|
|
|
|
if (red_up == 0 && red_threshold != 0) {
|
|
|
|
threshold_data.push({
|
|
|
|
// barWidth will be correct on draw time
|
|
|
|
id: "critical_up",
|
|
|
|
data: [[max_x, red_threshold]],
|
|
|
|
label: null,
|
|
|
|
color: critical,
|
|
|
|
bars: {
|
|
|
|
show: true,
|
|
|
|
align: "left",
|
|
|
|
barWidth: 1,
|
|
|
|
lineWidth: 0,
|
|
|
|
horizontal: true,
|
|
|
|
fillColor: { colors: [{ opacity: 0.1 }, { opacity: 0.1 }] }
|
|
|
|
},
|
|
|
|
highlightColor: "rgba(254, 236, 234, 0)"
|
|
|
|
});
|
|
|
|
extremes["critical_normal_1"] = red_threshold;
|
|
|
|
extremes["critical_normal_2"] = red_up;
|
|
|
|
} else {
|
|
|
|
threshold_data.push({
|
|
|
|
id: "critical_normal",
|
|
|
|
data: [[max_x, red_threshold]],
|
|
|
|
label: null,
|
|
|
|
color: critical,
|
|
|
|
bars: {
|
|
|
|
show: true,
|
|
|
|
align: "left",
|
|
|
|
barWidth: red_up - red_threshold,
|
|
|
|
lineWidth: 0,
|
|
|
|
horizontal: true,
|
|
|
|
fillColor: { colors: [{ opacity: 0.1 }, { opacity: 0.1 }] }
|
|
|
|
},
|
|
|
|
highlightColor: "rgba(254, 236, 234, 0)"
|
|
|
|
});
|
|
|
|
extremes["critical_normal_1"] = red_threshold;
|
|
|
|
extremes["critical_normal_2"] = red_up;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-05-09 16:26:38 +02:00
|
|
|
var stacked = null;
|
|
|
|
var filled_s = 0.3;
|
|
|
|
|
2019-01-30 12:27:18 +01:00
|
|
|
switch (type) {
|
|
|
|
case "line":
|
|
|
|
case 2:
|
2019-06-24 17:17:50 +02:00
|
|
|
stacked = null;
|
|
|
|
filled_s = false;
|
2019-01-30 12:27:18 +01:00
|
|
|
break;
|
|
|
|
case 3:
|
|
|
|
stacked = "stack";
|
|
|
|
filled_s = false;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
case "area":
|
|
|
|
case 0:
|
|
|
|
stacked = null;
|
|
|
|
filled_s = 0.3;
|
|
|
|
break;
|
|
|
|
case 1:
|
|
|
|
stacked = "stack";
|
|
|
|
filled_s = 0.3;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
var datas = new Array();
|
|
|
|
var data_base = new Array();
|
|
|
|
var lineWidth = $("#hidden-line_width_graph").val() || 1;
|
|
|
|
|
2019-05-09 16:26:38 +02:00
|
|
|
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;
|
|
|
|
|
2019-01-30 12:27:18 +01:00
|
|
|
$.each(values, function(index, value) {
|
|
|
|
if (typeof value.data !== "undefined") {
|
|
|
|
if (index.search("alert") >= 0) {
|
|
|
|
fill_color = "#ff7f00";
|
|
|
|
} else if (index.search("event") >= 0) {
|
|
|
|
fill_color = "#ff0000";
|
|
|
|
} else {
|
|
|
|
fill_color = "green";
|
|
|
|
}
|
|
|
|
|
2020-10-05 17:03:30 +02:00
|
|
|
if (typeof maximum_y_axis !== "undefined" && maximum_y_axis != 0) {
|
|
|
|
maximum_y_axis =
|
|
|
|
parseInt(value.max) > parseInt(maximum_y_axis)
|
|
|
|
? parseInt(value.max)
|
|
|
|
: parseInt(maximum_y_axis);
|
|
|
|
}
|
|
|
|
|
2019-01-30 12:27:18 +01:00
|
|
|
switch (series_type[index]) {
|
|
|
|
case "area":
|
|
|
|
line_show = true;
|
2019-05-09 16:26:38 +02:00
|
|
|
points_show = false;
|
2019-01-30 12:27:18 +01:00
|
|
|
filled = filled_s;
|
|
|
|
steps_chart = false;
|
|
|
|
radius = false;
|
|
|
|
fill_points = fill_color;
|
|
|
|
break;
|
|
|
|
case "percentil":
|
|
|
|
case "line":
|
|
|
|
default:
|
|
|
|
line_show = true;
|
|
|
|
points_show = false;
|
|
|
|
filled = false;
|
|
|
|
steps_chart = false;
|
|
|
|
radius = false;
|
|
|
|
fill_points = fill_color;
|
|
|
|
break;
|
|
|
|
case "points":
|
|
|
|
line_show = false;
|
|
|
|
points_show = true;
|
2020-09-15 11:13:41 +02:00
|
|
|
filled = true;
|
2019-05-09 16:26:38 +02:00
|
|
|
radius = 3;
|
2019-01-30 12:27:18 +01:00
|
|
|
fill_points = fill_color;
|
|
|
|
break;
|
|
|
|
case "unknown":
|
|
|
|
case "boolean":
|
|
|
|
line_show = true;
|
|
|
|
points_show = false;
|
|
|
|
filled = filled_s;
|
|
|
|
steps_chart = true;
|
|
|
|
radius = false;
|
|
|
|
fill_points = fill_color;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (series_type[index] != "boolean") {
|
|
|
|
if (value.slice_data) {
|
|
|
|
update_legend[index] = value.slice_data;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
//in graph stacked unset percentil
|
|
|
|
if (
|
|
|
|
!(type == 1 && /percentil/.test(index) == true) &&
|
|
|
|
!(type == 3 && /percentil/.test(index) == true)
|
|
|
|
) {
|
|
|
|
data_base.push({
|
|
|
|
id: "serie_" + i,
|
|
|
|
data: value.data,
|
|
|
|
label: index,
|
|
|
|
color: color[index]["color"],
|
|
|
|
lines: {
|
|
|
|
show: line_show,
|
|
|
|
fill: filled,
|
|
|
|
lineWidth: lineWidth,
|
|
|
|
steps: steps_chart
|
|
|
|
},
|
|
|
|
points: {
|
|
|
|
show: points_show,
|
2019-05-09 16:26:38 +02:00
|
|
|
radius: radius,
|
2020-09-15 11:13:41 +02:00
|
|
|
fillColor: fill_points,
|
|
|
|
fill: filled
|
2019-01-30 12:27:18 +01:00
|
|
|
},
|
|
|
|
legend: legend.index
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
i++;
|
|
|
|
});
|
|
|
|
|
|
|
|
// The first execution, the graph data is the base data
|
|
|
|
datas = data_base;
|
|
|
|
|
|
|
|
var number_ticks = 8;
|
|
|
|
if (vconsole) {
|
|
|
|
number_ticks = 5;
|
|
|
|
}
|
|
|
|
|
2019-05-09 16:26:38 +02:00
|
|
|
// masticks this variable is commented because the library defines the tick number by itself
|
|
|
|
// var maxticks = date_array["period"] / 3600 / number_ticks;
|
2019-01-30 12:27:18 +01:00
|
|
|
|
|
|
|
var options = {
|
|
|
|
series: {
|
|
|
|
stack: stacked,
|
|
|
|
shadowSize: 0.1
|
|
|
|
},
|
|
|
|
crosshair: {
|
|
|
|
mode: "xy",
|
|
|
|
color: "grey"
|
|
|
|
},
|
|
|
|
selection: {
|
|
|
|
mode: "xy",
|
|
|
|
color: "#777"
|
|
|
|
},
|
|
|
|
export: {
|
|
|
|
export_data: true,
|
|
|
|
labels_long: legend,
|
|
|
|
homeurl: homeurl
|
|
|
|
},
|
|
|
|
grid: {
|
|
|
|
hoverable: true,
|
|
|
|
clickable: true,
|
|
|
|
borderColor: "#C1C1C1",
|
2021-08-03 15:46:01 +02:00
|
|
|
color: grid_color
|
2019-01-30 12:27:18 +01:00
|
|
|
},
|
|
|
|
xaxis: {
|
|
|
|
min: min_x,
|
|
|
|
max: max_x,
|
|
|
|
font: {
|
|
|
|
size: font_size + 2,
|
|
|
|
color: legend_color,
|
2021-06-10 10:19:11 +02:00
|
|
|
family: "lato"
|
2019-01-30 12:27:18 +01:00
|
|
|
}
|
|
|
|
},
|
|
|
|
xaxes: [
|
|
|
|
{
|
|
|
|
mode: "time",
|
|
|
|
timezone: "browser",
|
|
|
|
localTimezone: true
|
|
|
|
//tickSize: [maxticks, 'hour']
|
|
|
|
}
|
|
|
|
],
|
|
|
|
yaxis: {
|
|
|
|
font: {
|
|
|
|
size: font_size + 2,
|
|
|
|
color: legend_color,
|
2021-06-10 10:19:11 +02:00
|
|
|
family: "lato",
|
2019-01-30 12:27:18 +01:00
|
|
|
variant: "small-caps"
|
|
|
|
}
|
|
|
|
},
|
|
|
|
yaxes: [
|
|
|
|
{
|
|
|
|
tickFormatter: yFormatter,
|
|
|
|
position: "left"
|
|
|
|
}
|
|
|
|
],
|
|
|
|
legend: {
|
|
|
|
position: "se",
|
|
|
|
container: $("#legend_" + graph_id),
|
|
|
|
labelFormatter: lFormatter
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2021-08-03 15:46:01 +02:00
|
|
|
if (basic_chart === true) {
|
|
|
|
options.grid.borderWidth = 0;
|
|
|
|
options.grid.backgroundColor = "rgba(255,255,255,0)";
|
|
|
|
options.grid.autoHighlight = false;
|
|
|
|
options.xaxis.show = false;
|
|
|
|
options.xaxis.tickLength = 0;
|
|
|
|
options.yaxis.show = false;
|
|
|
|
options.yaxis.tickLength = 0;
|
|
|
|
}
|
|
|
|
|
2020-10-05 17:03:30 +02:00
|
|
|
if (typeof maximum_y_axis !== "undefined" && maximum_y_axis != 0) {
|
|
|
|
options.yaxis.max = maximum_y_axis;
|
|
|
|
}
|
|
|
|
|
2019-01-30 12:27:18 +01:00
|
|
|
if (vconsole) {
|
|
|
|
options.grid["hoverable"] = false;
|
|
|
|
options.grid["clickable"] = false;
|
|
|
|
options.crosshair = false;
|
|
|
|
options.selection = false;
|
|
|
|
}
|
|
|
|
|
|
|
|
var plot = $.plot($("#" + graph_id), datas, options);
|
|
|
|
|
|
|
|
// Adjust the overview plot to the width and position of the main plot
|
|
|
|
adjust_left_width_canvas(graph_id, "overview_" + graph_id);
|
|
|
|
update_left_width_canvas(graph_id);
|
|
|
|
|
|
|
|
// Adjust overview when main chart is resized
|
|
|
|
$("#" + graph_id).resize(function() {
|
|
|
|
update_left_width_canvas(graph_id);
|
|
|
|
});
|
|
|
|
|
|
|
|
// Adjust linked graph to the width and position of the main plot
|
|
|
|
// Miniplot
|
|
|
|
if (!vconsole) {
|
|
|
|
var overview = $.plot($("#overview_" + graph_id), datas, {
|
|
|
|
series: {
|
|
|
|
stack: stacked,
|
|
|
|
shadowSize: 0.1
|
|
|
|
},
|
|
|
|
crosshair: {
|
|
|
|
mode: "xy"
|
|
|
|
},
|
|
|
|
selection: {
|
|
|
|
mode: "xy",
|
|
|
|
color: "#777"
|
|
|
|
},
|
|
|
|
export: {
|
|
|
|
export_data: true,
|
|
|
|
labels_long: legend,
|
|
|
|
homeurl: homeurl
|
|
|
|
},
|
|
|
|
grid: {
|
|
|
|
hoverable: true,
|
|
|
|
clickable: true,
|
|
|
|
borderWidth: 1,
|
|
|
|
borderColor: "#C1C1C1",
|
|
|
|
tickColor: background_color,
|
|
|
|
color: grid_color,
|
|
|
|
autoHighlight: true
|
|
|
|
},
|
|
|
|
xaxis: {
|
|
|
|
min: date_array.start_date * 1000,
|
|
|
|
max: date_array.final_date * 1000,
|
|
|
|
font: {
|
|
|
|
size: font_size + 2,
|
|
|
|
color: legend_color,
|
2021-06-10 10:19:11 +02:00
|
|
|
family: "lato"
|
2019-01-30 12:27:18 +01:00
|
|
|
}
|
|
|
|
},
|
|
|
|
xaxes: [
|
|
|
|
{
|
|
|
|
mode: "time",
|
|
|
|
timezone: "browser",
|
|
|
|
localTimezone: true
|
|
|
|
//tickSize: [maxticks, 'hour']
|
|
|
|
}
|
|
|
|
],
|
|
|
|
yaxis: {
|
|
|
|
font: {
|
|
|
|
size: font_size + 2,
|
|
|
|
color: legend_color,
|
2021-06-10 10:19:11 +02:00
|
|
|
family: "lato"
|
2019-01-30 12:27:18 +01:00
|
|
|
}
|
|
|
|
},
|
|
|
|
yaxes: [
|
|
|
|
{
|
|
|
|
tickFormatter: yFormatter,
|
|
|
|
position: "left"
|
|
|
|
}
|
|
|
|
],
|
|
|
|
legend: {
|
|
|
|
position: "se",
|
|
|
|
container: $("#legend_" + graph_id),
|
|
|
|
labelFormatter: lFormatter
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
// Adjust overview when main chart is resized
|
|
|
|
$("#overview_" + graph_id).resize(function() {
|
|
|
|
update_left_width_canvas(graph_id);
|
|
|
|
});
|
|
|
|
|
|
|
|
var max_draw = [];
|
|
|
|
max_draw["max"] = plot.getAxes().yaxis.max;
|
|
|
|
max_draw["min"] = plot.getAxes().yaxis.min;
|
|
|
|
|
|
|
|
// Connection between plot and miniplot
|
|
|
|
$("#" + graph_id).bind("plotselected", function(event, ranges) {
|
|
|
|
// do the zooming if exist menu to undo it
|
|
|
|
if (menu == 0) {
|
|
|
|
return;
|
|
|
|
}
|
2018-02-16 13:41:31 +01:00
|
|
|
|
2019-05-09 16:26:38 +02:00
|
|
|
var dataInSelection = ranges.xaxis.to - ranges.xaxis.from;
|
2018-07-30 16:16:08 +02:00
|
|
|
|
2019-01-30 12:27:18 +01:00
|
|
|
var maxticks_zoom = dataInSelection / 3600000 / number_ticks;
|
|
|
|
if (maxticks_zoom < 0.001) {
|
|
|
|
maxticks_zoom = dataInSelection / 60000 / number_ticks;
|
|
|
|
if (maxticks_zoom < 0.001) {
|
|
|
|
maxticks_zoom = 0;
|
|
|
|
}
|
|
|
|
}
|
2018-02-16 13:41:31 +01:00
|
|
|
|
2019-05-09 16:26:38 +02:00
|
|
|
var y_recal = "";
|
2019-01-30 12:27:18 +01:00
|
|
|
if (thresholded) {
|
2019-05-09 16:26:38 +02:00
|
|
|
y_recal = axis_thresholded(
|
2019-01-30 12:27:18 +01:00
|
|
|
threshold_data,
|
|
|
|
plot.getAxes().yaxis.min,
|
|
|
|
plot.getAxes().yaxis.max,
|
|
|
|
red_threshold,
|
|
|
|
extremes,
|
|
|
|
red_up
|
|
|
|
);
|
|
|
|
} else {
|
2019-05-09 16:26:38 +02:00
|
|
|
y_recal = ranges.yaxis;
|
2019-01-30 12:27:18 +01:00
|
|
|
}
|
2018-02-16 13:41:31 +01:00
|
|
|
|
2019-01-30 12:27:18 +01:00
|
|
|
if (thresholded) {
|
2022-05-18 17:17:31 +02:00
|
|
|
var data_base_threshold = add_threshold(
|
2019-01-30 12:27:18 +01:00
|
|
|
data_base,
|
|
|
|
threshold_data,
|
|
|
|
ranges.yaxis.from,
|
|
|
|
y_recal.max,
|
|
|
|
red_threshold,
|
|
|
|
extremes,
|
|
|
|
red_up,
|
|
|
|
markins_graph
|
|
|
|
);
|
|
|
|
|
|
|
|
plot = $.plot(
|
|
|
|
$("#" + graph_id),
|
2022-05-18 17:17:31 +02:00
|
|
|
data_base_threshold,
|
2019-01-30 12:27:18 +01:00
|
|
|
$.extend(true, {}, options, {
|
|
|
|
grid: {
|
|
|
|
borderWidth: 1,
|
|
|
|
hoverable: true,
|
|
|
|
autoHighlight: true
|
|
|
|
},
|
|
|
|
xaxis: {
|
|
|
|
min: ranges.xaxis.from,
|
|
|
|
max: ranges.xaxis.to,
|
|
|
|
font: {
|
|
|
|
size: font_size + 2,
|
|
|
|
color: legend_color,
|
2021-06-10 10:19:11 +02:00
|
|
|
family: "lato"
|
2019-01-30 12:27:18 +01:00
|
|
|
}
|
|
|
|
},
|
|
|
|
xaxes: [
|
|
|
|
{
|
|
|
|
mode: "time",
|
|
|
|
timezone: "browser",
|
|
|
|
localTimezone: true,
|
|
|
|
tickSize: [maxticks_zoom, "hour"]
|
|
|
|
}
|
|
|
|
],
|
|
|
|
yaxis: {
|
|
|
|
min: ranges.yaxis.from,
|
|
|
|
max: y_recal.max,
|
|
|
|
font: {
|
|
|
|
size: font_size + 2,
|
|
|
|
color: legend_color,
|
2021-06-10 10:19:11 +02:00
|
|
|
family: "lato"
|
2019-01-30 12:27:18 +01:00
|
|
|
}
|
|
|
|
},
|
|
|
|
yaxes: [
|
|
|
|
{
|
|
|
|
tickFormatter: yFormatter,
|
|
|
|
position: "left"
|
|
|
|
}
|
|
|
|
],
|
|
|
|
legend: {
|
|
|
|
show: true
|
|
|
|
}
|
|
|
|
})
|
|
|
|
);
|
|
|
|
} else {
|
|
|
|
plot = $.plot(
|
|
|
|
$("#" + graph_id),
|
|
|
|
data_base,
|
|
|
|
$.extend(true, {}, options, {
|
|
|
|
grid: {
|
|
|
|
borderWidth: 1,
|
|
|
|
hoverable: true,
|
|
|
|
autoHighlight: true
|
|
|
|
},
|
|
|
|
xaxis: {
|
|
|
|
min: ranges.xaxis.from,
|
|
|
|
max: ranges.xaxis.to,
|
|
|
|
font: {
|
|
|
|
size: font_size + 2,
|
|
|
|
color: legend_color,
|
2021-06-10 10:19:11 +02:00
|
|
|
family: "lato"
|
2019-01-30 12:27:18 +01:00
|
|
|
}
|
|
|
|
},
|
|
|
|
xaxes: [
|
|
|
|
{
|
|
|
|
mode: "time",
|
|
|
|
timezone: "browser",
|
|
|
|
localTimezone: true,
|
|
|
|
tickSize: [maxticks_zoom, "hour"]
|
|
|
|
}
|
|
|
|
],
|
|
|
|
yaxis: {
|
|
|
|
min: ranges.yaxis.from,
|
|
|
|
max: ranges.yaxis.to,
|
|
|
|
font: {
|
|
|
|
size: font_size + 2,
|
|
|
|
color: legend_color,
|
2021-06-10 10:19:11 +02:00
|
|
|
family: "lato"
|
2019-01-30 12:27:18 +01:00
|
|
|
}
|
|
|
|
},
|
|
|
|
yaxes: [
|
|
|
|
{
|
|
|
|
tickFormatter: yFormatter,
|
|
|
|
position: "left"
|
|
|
|
}
|
|
|
|
],
|
|
|
|
legend: {
|
|
|
|
show: true
|
|
|
|
}
|
|
|
|
})
|
|
|
|
);
|
|
|
|
}
|
2018-02-16 13:41:31 +01:00
|
|
|
|
2019-01-30 12:27:18 +01:00
|
|
|
$("#menu_cancelzoom_" + graph_id).attr(
|
|
|
|
"src",
|
|
|
|
homeurl + "images/zoom_cross_grey.png"
|
|
|
|
);
|
|
|
|
|
|
|
|
max_draw["max"] = ranges.yaxis.to;
|
|
|
|
max_draw["min"] = ranges.yaxis.from;
|
|
|
|
|
|
|
|
// don't fire event on the overview to prevent eternal loop
|
|
|
|
overview.setSelection(ranges, true);
|
|
|
|
});
|
|
|
|
|
|
|
|
$("#overview_" + graph_id).bind("plotselected", function(event, ranges) {
|
|
|
|
plot.setSelection(ranges);
|
|
|
|
});
|
|
|
|
|
|
|
|
var updateLegendTimeout = null;
|
|
|
|
var latestPosition = null;
|
|
|
|
var currentPlot = null;
|
|
|
|
|
|
|
|
// Update legend with the data of the plot in the mouse position
|
|
|
|
function updateLegend() {
|
|
|
|
updateLegendTimeout = null;
|
|
|
|
var pos = latestPosition;
|
|
|
|
var axes = currentPlot.getAxes();
|
|
|
|
if (
|
|
|
|
pos.x < axes.xaxis.min ||
|
|
|
|
pos.x > axes.xaxis.max ||
|
|
|
|
pos.y < axes.yaxis.min ||
|
|
|
|
pos.y > axes.yaxis.max
|
|
|
|
) {
|
|
|
|
return;
|
|
|
|
}
|
2018-02-16 13:41:31 +01:00
|
|
|
|
2019-01-30 12:27:18 +01:00
|
|
|
$("#timestamp_" + graph_id).show();
|
|
|
|
|
|
|
|
var d = new Date(pos.x);
|
|
|
|
var monthNames = [
|
|
|
|
"Jan",
|
|
|
|
"Feb",
|
|
|
|
"Mar",
|
|
|
|
"Apr",
|
|
|
|
"May",
|
|
|
|
"Jun",
|
|
|
|
"Jul",
|
|
|
|
"Aug",
|
|
|
|
"Sep",
|
|
|
|
"Oct",
|
|
|
|
"Nov",
|
|
|
|
"Dec"
|
|
|
|
];
|
|
|
|
|
2019-05-09 16:26:38 +02:00
|
|
|
var date_format =
|
2019-01-30 12:27:18 +01:00
|
|
|
(d.getDate() < 10 ? "0" : "") +
|
|
|
|
d.getDate() +
|
|
|
|
" " +
|
|
|
|
monthNames[d.getMonth()] +
|
|
|
|
" " +
|
|
|
|
d.getFullYear() +
|
|
|
|
"\n" +
|
|
|
|
(d.getHours() < 10 ? "0" : "") +
|
|
|
|
d.getHours() +
|
|
|
|
":" +
|
|
|
|
(d.getMinutes() < 10 ? "0" : "") +
|
|
|
|
d.getMinutes() +
|
|
|
|
":" +
|
|
|
|
(d.getSeconds() < 10 ? "0" : "") +
|
|
|
|
d.getSeconds();
|
|
|
|
|
|
|
|
$("#timestamp_" + graph_id).text(date_format);
|
|
|
|
|
|
|
|
var timesize = $("#timestamp_" + graph_id).width();
|
|
|
|
|
2019-05-09 16:26:38 +02:00
|
|
|
var dataset = currentPlot.getData();
|
2019-01-30 12:27:18 +01:00
|
|
|
|
|
|
|
var timenewpos =
|
|
|
|
dataset[0].xaxis.p2c(pos.x) +
|
|
|
|
$(".yAxis>div")
|
|
|
|
.eq(0)
|
|
|
|
.width();
|
|
|
|
var canvaslimit = $("#" + graph_id).width();
|
|
|
|
|
|
|
|
$("#timestamp_" + graph_id).css(
|
|
|
|
"top",
|
|
|
|
currentPlot.getPlotOffset().top -
|
|
|
|
$("#timestamp_" + graph_id).height() +
|
|
|
|
$("#legend_" + graph_id).height()
|
|
|
|
);
|
|
|
|
|
2021-04-09 11:52:28 +02:00
|
|
|
$("#timestamp_" + graph_id).css("color", "#000");
|
2019-01-30 12:27:18 +01:00
|
|
|
$("#timestamp_" + graph_id).css("font-size", font_size + 2 + "px");
|
2021-06-10 10:19:11 +02:00
|
|
|
$("#timestamp_" + graph_id).css("font-family", font);
|
2019-01-30 12:27:18 +01:00
|
|
|
|
|
|
|
if (timesize + timenewpos > canvaslimit) {
|
|
|
|
$("#timestamp_" + graph_id).css("left", timenewpos - timesize);
|
|
|
|
} else {
|
|
|
|
$("#timestamp_" + graph_id).css("left", timenewpos);
|
|
|
|
}
|
2018-02-27 16:28:00 +01:00
|
|
|
|
2019-01-30 12:27:18 +01:00
|
|
|
var i = 0;
|
2019-05-09 16:26:38 +02:00
|
|
|
for (var k = 0; k < dataset.length; k++) {
|
2019-01-30 12:27:18 +01:00
|
|
|
// k is the real series counter
|
|
|
|
// i is the series counter without thresholds
|
|
|
|
var series = dataset[k];
|
|
|
|
if (series.label == null) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
// find the nearest points, x-wise
|
2019-05-09 16:26:38 +02:00
|
|
|
for (var j = 0; j < series.data.length; ++j) {
|
2019-01-30 12:27:18 +01:00
|
|
|
if (series.data[j][0] > pos.x) {
|
|
|
|
break;
|
|
|
|
}
|
2018-02-27 16:28:00 +01:00
|
|
|
|
2019-01-30 12:27:18 +01:00
|
|
|
if (series.data[j]) {
|
|
|
|
var y = series.data[j][1];
|
2021-03-04 11:29:52 +01:00
|
|
|
var x = Math.round(series.data[j][0]);
|
2019-01-30 12:27:18 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
var data_legend = [];
|
|
|
|
|
|
|
|
// The graphs of points type and unknown graphs will dont be updated
|
|
|
|
if (
|
|
|
|
series_type[dataset[k]["label"]] != "points" &&
|
|
|
|
series_type[dataset[k]["label"]] != "unknown" &&
|
|
|
|
series_type[dataset[k]["label"]] != "percentil"
|
|
|
|
) {
|
2019-05-09 16:26:38 +02:00
|
|
|
var label_aux = "";
|
2019-01-30 12:27:18 +01:00
|
|
|
if (Object.keys(update_legend).length == 0) {
|
2019-05-09 16:26:38 +02:00
|
|
|
label_aux = legend[series.label];
|
2019-01-30 12:27:18 +01:00
|
|
|
|
|
|
|
$("#legend_" + graph_id + " .legendLabel")
|
|
|
|
.eq(i)
|
|
|
|
.html(
|
|
|
|
label_aux +
|
|
|
|
" value = " +
|
2019-12-05 17:41:44 +01:00
|
|
|
number_format(y, 0, "", short_data, divisor) +
|
2019-01-30 12:27:18 +01:00
|
|
|
" " +
|
|
|
|
unit
|
|
|
|
);
|
|
|
|
} else {
|
|
|
|
$.each(update_legend, function(index, value) {
|
2020-10-07 16:03:52 +02:00
|
|
|
if (typeof value[x] !== "undefined") {
|
|
|
|
data_legend[index] =
|
|
|
|
" Min: " +
|
|
|
|
number_format(value[x].min, 0, unit, short_data, divisor) +
|
|
|
|
" Max: " +
|
|
|
|
number_format(value[x].max, 0, unit, short_data, divisor) +
|
|
|
|
" Avg: " +
|
|
|
|
number_format(value[x].avg, 0, unit, short_data, divisor);
|
2022-05-12 09:10:39 +02:00
|
|
|
} else {
|
|
|
|
data_legend[index] = " Min: " + 0 + " Max: " + 0 + " Avg: " + 0;
|
2019-01-30 12:27:18 +01:00
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2020-10-07 16:03:52 +02:00
|
|
|
if (typeof data_legend[series.label] !== "undefined") {
|
|
|
|
label_aux =
|
|
|
|
legend[series.label].split(": Min")[0] +
|
|
|
|
": " +
|
|
|
|
data_legend[series.label];
|
|
|
|
$("#legend_" + graph_id + " .legendLabel")
|
|
|
|
.eq(i)
|
|
|
|
.html(label_aux);
|
|
|
|
}
|
2019-01-30 12:27:18 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
$("#legend_" + graph_id + " .legendLabel")
|
|
|
|
.eq(i)
|
|
|
|
.css("color", legend_color);
|
|
|
|
$("#legend_" + graph_id + " .legendLabel")
|
|
|
|
.eq(i)
|
|
|
|
.css("font-size", font_size + 2 + "px");
|
|
|
|
$("#legend_" + graph_id + " .legendLabel")
|
|
|
|
.eq(i)
|
2021-06-10 10:19:11 +02:00
|
|
|
.css("font-family", font);
|
2019-01-30 12:27:18 +01:00
|
|
|
|
|
|
|
i++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Events
|
2019-05-09 16:26:38 +02:00
|
|
|
$("#overview_" + graph_id).bind("plothover", function(event, pos) {
|
2019-01-30 12:27:18 +01:00
|
|
|
plot.setCrosshair({ x: pos.x, y: pos.y });
|
|
|
|
currentPlot = plot;
|
|
|
|
latestPosition = pos;
|
|
|
|
if (!updateLegendTimeout) {
|
|
|
|
updateLegendTimeout = setTimeout(updateLegend, 50);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2019-05-09 16:26:38 +02:00
|
|
|
$("#" + graph_id).bind("plothover", function(event, pos) {
|
2019-01-30 12:27:18 +01:00
|
|
|
overview.setCrosshair({ x: pos.x, y: pos.y });
|
|
|
|
currentPlot = plot;
|
|
|
|
latestPosition = pos;
|
|
|
|
if (!updateLegendTimeout) {
|
|
|
|
updateLegendTimeout = setTimeout(updateLegend, 50);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
$("#" + graph_id).bind("plotclick", function(event, pos, item) {
|
|
|
|
plot.unhighlight();
|
|
|
|
if (
|
|
|
|
item &&
|
|
|
|
item.series.label != "" &&
|
|
|
|
item.series.label != null &&
|
|
|
|
(item.series.label.search("alert") >= 0 ||
|
|
|
|
item.series.label.search("event") >= 0)
|
|
|
|
) {
|
|
|
|
plot.unhighlight();
|
|
|
|
|
|
|
|
$("#extra_" + graph_id).css("width", "170px");
|
2020-09-15 11:13:41 +02:00
|
|
|
$("#extra_" + graph_id).css("height", "auto");
|
2019-01-30 12:27:18 +01:00
|
|
|
|
|
|
|
var extra_info = "<i>No info to show</i>";
|
|
|
|
var extra_show = false;
|
|
|
|
var extra_height = $("#extra_" + graph_id).height();
|
|
|
|
var extra_width = parseInt(
|
|
|
|
$("#extra_" + graph_id)
|
|
|
|
.css("width")
|
|
|
|
.split("px")[0]
|
|
|
|
);
|
|
|
|
var events_data = new Array();
|
|
|
|
var offset_graph = plot.getPlotOffset();
|
|
|
|
var offset_relative = plot.offset();
|
|
|
|
var width_graph = plot.width();
|
|
|
|
var height_legend = $("#legend_" + graph_id).height();
|
|
|
|
var coord_x = pos.pageX - offset_relative.left + offset_graph.left;
|
2020-09-15 11:13:41 +02:00
|
|
|
var coord_y = offset_graph.top + height_legend + extra_height + 50;
|
2019-01-30 12:27:18 +01:00
|
|
|
|
|
|
|
if (coord_x + extra_width > width_graph) {
|
|
|
|
coord_x = coord_x - extra_width;
|
|
|
|
}
|
|
|
|
|
|
|
|
$("#extra_" + graph_id).css("left", coord_x);
|
|
|
|
$("#extra_" + graph_id).css("top", coord_y);
|
|
|
|
|
|
|
|
if (
|
|
|
|
item.series.label.search("alert") >= 0 ||
|
|
|
|
item.series.label.search("event") >= 0
|
|
|
|
) {
|
|
|
|
$.each(events_array, function(i, v) {
|
|
|
|
$.each(v, function(index, value) {
|
|
|
|
if (
|
|
|
|
value.utimestamp == item.datapoint[0] / 1000 ||
|
|
|
|
value.utimestamp == item.datapoint[0] / 1000 - 1
|
|
|
|
) {
|
|
|
|
events_data = value;
|
|
|
|
}
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2019-05-09 16:26:38 +02:00
|
|
|
var extra_color = "#ffffff";
|
2019-01-30 12:27:18 +01:00
|
|
|
if (events_data.event_type.search("alert") >= 0) {
|
2019-05-09 16:26:38 +02:00
|
|
|
extra_color = "#FFA631";
|
2019-01-30 12:27:18 +01:00
|
|
|
} else if (events_data.event_type.search("critical") >= 0) {
|
2019-06-04 14:08:07 +02:00
|
|
|
extra_color = "#e63c52";
|
2019-01-30 12:27:18 +01:00
|
|
|
} else if (events_data.event_type.search("warning") >= 0) {
|
2019-06-04 14:08:07 +02:00
|
|
|
extra_color = "#f3b200";
|
2019-01-30 12:27:18 +01:00
|
|
|
} else if (events_data.event_type.search("unknown") >= 0) {
|
2019-06-04 14:08:07 +02:00
|
|
|
extra_color = "#4a83f3";
|
2019-01-30 12:27:18 +01:00
|
|
|
} else if (events_data.event_type.search("normal") >= 0) {
|
2019-06-04 14:08:07 +02:00
|
|
|
extra_color = "#82b92e";
|
2019-01-30 12:27:18 +01:00
|
|
|
} else {
|
2019-05-09 16:26:38 +02:00
|
|
|
extra_color = "#ffffff";
|
2019-01-30 12:27:18 +01:00
|
|
|
}
|
2018-02-16 13:41:31 +01:00
|
|
|
|
2019-05-09 16:26:38 +02:00
|
|
|
$("#extra_" + graph_id).css("background-color", extra_color);
|
2019-01-30 12:27:18 +01:00
|
|
|
|
|
|
|
extra_info = "<b>" + events_data.evento + ":";
|
|
|
|
extra_info +=
|
|
|
|
'<br><br><span style="font-weight: normal;">Time: ' +
|
|
|
|
events_data.timestamp;
|
|
|
|
extra_show = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (extra_show) {
|
|
|
|
$("#extra_" + graph_id).html(extra_info);
|
|
|
|
$("#extra_" + graph_id).css("display", "");
|
|
|
|
}
|
|
|
|
plot.highlight(item.series, item.datapoint);
|
|
|
|
} else {
|
|
|
|
$("#extra_" + graph_id).html("");
|
|
|
|
$("#extra_" + graph_id).css("display", "none");
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
if (!vconsole) {
|
|
|
|
$("#" + graph_id).bind("mouseout", resetInteractivity);
|
|
|
|
$("#overview_" + graph_id).bind("mouseout", resetInteractivity);
|
|
|
|
}
|
|
|
|
|
2022-05-18 17:17:31 +02:00
|
|
|
if (image_threshold) {
|
2019-05-09 16:26:38 +02:00
|
|
|
var y_recal = plot.getAxes().yaxis.max;
|
2019-01-30 12:27:18 +01:00
|
|
|
if (!thresholded) {
|
|
|
|
// Recalculate the y axis
|
2019-05-09 16:26:38 +02:00
|
|
|
y_recal = axis_thresholded(
|
2019-01-30 12:27:18 +01:00
|
|
|
threshold_data,
|
|
|
|
plot.getAxes().yaxis.min,
|
|
|
|
plot.getAxes().yaxis.max,
|
|
|
|
red_threshold,
|
|
|
|
extremes,
|
|
|
|
red_up
|
|
|
|
);
|
|
|
|
}
|
2018-02-27 16:28:00 +01:00
|
|
|
|
2022-05-18 17:17:31 +02:00
|
|
|
var datas_threshold = add_threshold(
|
2019-01-30 12:27:18 +01:00
|
|
|
data_base,
|
|
|
|
threshold_data,
|
|
|
|
plot.getAxes().yaxis.min,
|
|
|
|
y_recal.max,
|
|
|
|
red_threshold,
|
|
|
|
extremes,
|
|
|
|
red_up,
|
|
|
|
markins_graph
|
|
|
|
);
|
|
|
|
|
|
|
|
plot = $.plot(
|
|
|
|
$("#" + graph_id),
|
2022-05-18 17:17:31 +02:00
|
|
|
datas_threshold,
|
2019-01-30 12:27:18 +01:00
|
|
|
$.extend(true, {}, options, {
|
|
|
|
yaxis: {
|
|
|
|
max: y_recal.max
|
|
|
|
},
|
|
|
|
xaxis: {
|
|
|
|
min: plot.getAxes().xaxis.min,
|
|
|
|
max: plot.getAxes().xaxis.max
|
|
|
|
}
|
|
|
|
})
|
|
|
|
);
|
|
|
|
|
|
|
|
thresholded = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Reset interactivity styles
|
|
|
|
function resetInteractivity() {
|
|
|
|
$("#timestamp_" + graph_id).hide();
|
2019-05-09 16:26:38 +02:00
|
|
|
var dataset = plot.getData();
|
2019-01-30 12:27:18 +01:00
|
|
|
for (i = 0; i < dataset.length; ++i) {
|
|
|
|
var series = dataset[i];
|
|
|
|
var label_aux = legend[series.label];
|
|
|
|
$("#legend_" + graph_id + " .legendLabel")
|
|
|
|
.eq(i)
|
|
|
|
.html(label_aux);
|
|
|
|
}
|
|
|
|
$("#legend_" + graph_id + " .legendLabel").css("color", legend_color);
|
|
|
|
$("#legend_" + graph_id + " .legendLabel").css(
|
|
|
|
"font-size",
|
|
|
|
font_size + 2 + "px"
|
|
|
|
);
|
2021-06-10 10:19:11 +02:00
|
|
|
$("#legend_" + graph_id + " .legendLabel").css("font-family", font);
|
2019-01-30 12:27:18 +01:00
|
|
|
|
|
|
|
plot.clearCrosshair();
|
|
|
|
overview.clearCrosshair();
|
|
|
|
}
|
|
|
|
|
2019-05-09 16:26:38 +02:00
|
|
|
function yFormatter(v) {
|
|
|
|
var formatted = v;
|
2019-12-05 17:41:44 +01:00
|
|
|
|
2019-01-30 12:27:18 +01:00
|
|
|
if (short_data) {
|
2019-12-05 17:41:44 +01:00
|
|
|
formatted = number_format(v, force_integer, unit, short_data, divisor);
|
2019-01-30 12:27:18 +01:00
|
|
|
} else {
|
2019-07-08 13:23:35 +02:00
|
|
|
// It is an integer.
|
2019-01-30 12:27:18 +01:00
|
|
|
if (v - Math.floor(v) == 0) {
|
2019-12-05 17:41:44 +01:00
|
|
|
formatted = number_format(v, force_integer, unit, 2, divisor);
|
2019-01-30 12:27:18 +01:00
|
|
|
}
|
|
|
|
}
|
2018-02-23 14:31:00 +01:00
|
|
|
|
2019-07-08 13:23:35 +02:00
|
|
|
// Get only two decimals.
|
|
|
|
if (typeof formatted != "string") {
|
|
|
|
formatted = Math.round(formatted * 100) / 100;
|
|
|
|
}
|
2019-01-30 12:27:18 +01:00
|
|
|
return formatted;
|
|
|
|
}
|
2018-06-14 10:02:26 +02:00
|
|
|
|
2019-05-09 16:26:38 +02:00
|
|
|
function lFormatter(v) {
|
2020-10-07 16:03:52 +02:00
|
|
|
var style =
|
|
|
|
"color:" +
|
|
|
|
legend_color +
|
2021-06-10 10:19:11 +02:00
|
|
|
"; font-family: " +
|
|
|
|
"lato" +
|
2020-10-07 16:03:52 +02:00
|
|
|
"Font; font-size:" +
|
|
|
|
(parseInt(font_size) + 2) +
|
|
|
|
"px;";
|
2021-06-10 10:19:11 +02:00
|
|
|
return '<span style="' + style + '" class="lato">' + legend[v] + "</span>";
|
2019-01-30 12:27:18 +01:00
|
|
|
}
|
2018-02-23 14:31:00 +01:00
|
|
|
|
2019-01-30 12:27:18 +01:00
|
|
|
$("#overview_" + graph_id).css("display", "none");
|
2018-06-06 17:23:32 +02:00
|
|
|
|
2019-01-30 12:27:18 +01:00
|
|
|
if (menu) {
|
|
|
|
var parent_height;
|
|
|
|
$("#menu_overview_" + graph_id).click(function() {
|
|
|
|
$("#overview_" + graph_id).toggle();
|
|
|
|
});
|
2016-05-26 08:57:33 +02:00
|
|
|
|
2019-01-30 12:27:18 +01:00
|
|
|
$("#menu_export_csv_" + graph_id).click(function(e) {
|
|
|
|
e.preventDefault();
|
|
|
|
plot.exportDataCSV();
|
|
|
|
var es_firefox =
|
|
|
|
navigator.userAgent.toLowerCase().indexOf("firefox") > -1;
|
|
|
|
if (es_firefox) {
|
|
|
|
$("#dialog")
|
|
|
|
.css("visibility", "visible")
|
|
|
|
.dialog();
|
|
|
|
}
|
|
|
|
delete data_base[0].threshold;
|
|
|
|
plot = $.plot(
|
|
|
|
$("#" + graph_id),
|
|
|
|
data_base,
|
|
|
|
$.extend(true, {}, options, {
|
|
|
|
legend: { show: true }
|
|
|
|
})
|
|
|
|
);
|
|
|
|
});
|
2018-02-16 13:41:31 +01:00
|
|
|
|
2019-01-30 12:27:18 +01:00
|
|
|
$("#menu_threshold_" + graph_id).click(function() {
|
|
|
|
datas = new Array();
|
|
|
|
if (thresholded) {
|
|
|
|
$.each(data_base, function() {
|
|
|
|
datas.push(this);
|
|
|
|
});
|
|
|
|
|
|
|
|
delete data_base[0].threshold;
|
|
|
|
|
|
|
|
plot = $.plot(
|
|
|
|
$("#" + graph_id),
|
|
|
|
data_base,
|
|
|
|
$.extend(true, {}, options, {
|
|
|
|
yaxis: {
|
|
|
|
min: max_draw["min"],
|
|
|
|
max: max_draw["max"]
|
|
|
|
},
|
|
|
|
xaxis: {
|
|
|
|
min: plot.getAxes().xaxis.min,
|
|
|
|
max: plot.getAxes().xaxis.max
|
|
|
|
}
|
|
|
|
})
|
|
|
|
);
|
|
|
|
thresholded = false;
|
|
|
|
} else {
|
2019-05-09 16:26:38 +02:00
|
|
|
var y_recal = plot.getAxes().yaxis.max;
|
2019-01-30 12:27:18 +01:00
|
|
|
if (!thresholded) {
|
|
|
|
// Recalculate the y axis
|
2019-05-09 16:26:38 +02:00
|
|
|
y_recal = axis_thresholded(
|
2019-01-30 12:27:18 +01:00
|
|
|
threshold_data,
|
|
|
|
plot.getAxes().yaxis.min,
|
|
|
|
plot.getAxes().yaxis.max,
|
|
|
|
red_threshold,
|
|
|
|
extremes,
|
|
|
|
red_up
|
|
|
|
);
|
|
|
|
}
|
2018-02-27 16:28:00 +01:00
|
|
|
|
2022-05-18 17:17:31 +02:00
|
|
|
datas_threshold = add_threshold(
|
2019-01-30 12:27:18 +01:00
|
|
|
data_base,
|
|
|
|
threshold_data,
|
|
|
|
plot.getAxes().yaxis.min,
|
|
|
|
y_recal.max,
|
|
|
|
red_threshold,
|
|
|
|
extremes,
|
|
|
|
red_up,
|
|
|
|
markins_graph
|
|
|
|
);
|
|
|
|
|
|
|
|
plot = $.plot(
|
|
|
|
$("#" + graph_id),
|
2022-05-18 17:17:31 +02:00
|
|
|
datas_threshold,
|
2019-01-30 12:27:18 +01:00
|
|
|
$.extend(true, {}, options, {
|
|
|
|
yaxis: {
|
|
|
|
min: max_draw["min"],
|
|
|
|
max: y_recal.max
|
|
|
|
},
|
|
|
|
xaxis: {
|
|
|
|
min: plot.getAxes().xaxis.min,
|
|
|
|
max: plot.getAxes().xaxis.max
|
|
|
|
}
|
|
|
|
})
|
|
|
|
);
|
2018-02-16 13:41:31 +01:00
|
|
|
|
2019-01-30 12:27:18 +01:00
|
|
|
thresholded = true;
|
|
|
|
}
|
|
|
|
});
|
2018-02-16 13:41:31 +01:00
|
|
|
|
2019-01-30 12:27:18 +01:00
|
|
|
$("#menu_cancelzoom_" + graph_id).click(function() {
|
|
|
|
// cancel the zooming
|
|
|
|
delete data_base[0].threshold;
|
|
|
|
plot = $.plot(
|
|
|
|
$("#" + graph_id),
|
|
|
|
data_base,
|
|
|
|
$.extend(true, {}, options, {
|
|
|
|
legend: { show: true }
|
|
|
|
})
|
|
|
|
);
|
|
|
|
$("#menu_cancelzoom_" + graph_id).attr(
|
|
|
|
"src",
|
|
|
|
homeurl + "images/zoom_cross.disabled.png"
|
|
|
|
);
|
2021-03-11 15:40:23 +01:00
|
|
|
$("#menu_cancelzoom_" + graph_id).attr("class", "invert_filter");
|
2019-01-30 12:27:18 +01:00
|
|
|
overview.clearSelection();
|
|
|
|
thresholded = false;
|
|
|
|
max_draw = [];
|
|
|
|
});
|
2018-02-16 13:41:31 +01:00
|
|
|
|
2019-01-30 12:27:18 +01:00
|
|
|
// Adjust the menu image on top of the plot
|
|
|
|
// If there is no legend we increase top-padding to make space to the menu
|
|
|
|
if (legend.length == 0) {
|
|
|
|
$("#menu_" + graph_id)
|
|
|
|
.parent()
|
|
|
|
.css("padding-top", $("#menu_" + graph_id).css("height"));
|
|
|
|
}
|
2018-02-16 13:41:31 +01:00
|
|
|
|
2019-01-30 12:27:18 +01:00
|
|
|
// Add bottom margin in the legend
|
|
|
|
// Estimated height of 24 (works fine with this data in all browsers)
|
|
|
|
$("#legend_" + graph_id).css("margin-bottom", "10px");
|
|
|
|
parent_height = parseInt(
|
|
|
|
$("#menu_" + graph_id)
|
|
|
|
.parent()
|
|
|
|
.css("height")
|
|
|
|
.split("px")[0]
|
|
|
|
);
|
|
|
|
adjust_menu(graph_id, plot, parent_height, width, show_legend);
|
|
|
|
}
|
2016-05-26 08:57:33 +02:00
|
|
|
}
|
|
|
|
|
2019-01-30 12:27:18 +01:00
|
|
|
function format_unit_yaxes(y) {
|
|
|
|
var how_bigger = [];
|
|
|
|
|
|
|
|
if (y > 1000000) {
|
|
|
|
how_bigger["unit"] = "M";
|
|
|
|
how_bigger["y"] = y / 1000000;
|
|
|
|
} else if (y > 1000) {
|
|
|
|
how_bigger["unit"] = "K";
|
|
|
|
how_bigger["y"] = y / 1000;
|
|
|
|
} else if (y < -1000000) {
|
|
|
|
how_bigger["unit"] = "M";
|
|
|
|
how_bigger["y"] = y / 1000000;
|
|
|
|
} else if (y < -1000) {
|
|
|
|
how_bigger["unit"] = "K";
|
|
|
|
how_bigger["y"] = y / 1000;
|
|
|
|
} else {
|
|
|
|
how_bigger["unit"] = "";
|
|
|
|
how_bigger["y"] = y;
|
|
|
|
}
|
|
|
|
|
|
|
|
return how_bigger;
|
2018-07-05 11:52:52 +02:00
|
|
|
}
|
|
|
|
|
2018-06-06 11:18:39 +02:00
|
|
|
function adjust_menu(graph_id, plot, parent_height, width, show_legend) {
|
2019-05-09 16:26:38 +02:00
|
|
|
var left_ticks_width = 0;
|
2019-01-30 12:27:18 +01:00
|
|
|
if (
|
|
|
|
$("#" + graph_id + " .xAxis .tickLabel")
|
|
|
|
.eq(0)
|
|
|
|
.css("width") != undefined
|
|
|
|
) {
|
|
|
|
left_ticks_width = $("#" + graph_id + " .xAxis .tickLabel")
|
|
|
|
.eq(0)
|
|
|
|
.css("width")
|
|
|
|
.split("px")[0];
|
|
|
|
}
|
|
|
|
|
2019-05-09 16:26:38 +02:00
|
|
|
var legend_height = 0;
|
2019-01-30 12:27:18 +01:00
|
|
|
if (show_legend) {
|
2019-05-09 16:26:38 +02:00
|
|
|
legend_height =
|
2019-01-30 12:27:18 +01:00
|
|
|
parseInt(
|
|
|
|
$("#legend_" + graph_id)
|
|
|
|
.css("height")
|
|
|
|
.split("px")[0]
|
|
|
|
) +
|
|
|
|
parseInt(
|
|
|
|
$("#legend_" + graph_id)
|
|
|
|
.css("margin-top")
|
|
|
|
.split("px")[0]
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
var menu_height = "25";
|
|
|
|
if (
|
|
|
|
$("#menu_" + graph_id).height() != undefined &&
|
|
|
|
$("#menu_" + graph_id).height() > 20
|
|
|
|
) {
|
|
|
|
menu_height = $("#menu_" + graph_id).height();
|
|
|
|
}
|
|
|
|
|
2019-05-09 16:26:38 +02:00
|
|
|
var offset = $("#" + graph_id)[0].offsetTop;
|
2019-01-30 12:27:18 +01:00
|
|
|
|
|
|
|
$("#menu_" + graph_id).css("top", offset + "px");
|
|
|
|
|
|
|
|
$("#menu_" + graph_id).show();
|
2016-05-26 08:57:33 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
function set_watermark(graph_id, plot, watermark_src) {
|
2019-01-30 12:27:18 +01:00
|
|
|
var img = new Image();
|
|
|
|
|
|
|
|
img.src = watermark_src;
|
|
|
|
var context = plot.getCanvas().getContext("2d");
|
|
|
|
|
|
|
|
// Once it's loaded draw the image on the canvas.
|
|
|
|
img.addEventListener(
|
|
|
|
"load",
|
|
|
|
function() {
|
|
|
|
// Now resize the image: x, y, w, h.
|
|
|
|
var down_ticks_height = 0;
|
|
|
|
if (
|
|
|
|
$("#" + graph_id + " .yAxis .tickLabel")
|
|
|
|
.eq(0)
|
|
|
|
.css("height") != undefined
|
|
|
|
) {
|
|
|
|
down_ticks_height = $("#" + graph_id + " .yAxis .tickLabel")
|
|
|
|
.eq(0)
|
|
|
|
.css("height")
|
|
|
|
.split("px")[0];
|
|
|
|
}
|
|
|
|
|
|
|
|
var left_pos =
|
|
|
|
parseInt(context.canvas.width) -
|
|
|
|
$("#watermark_image_" + graph_id)[0].width -
|
|
|
|
30;
|
|
|
|
var top_pos = 7;
|
|
|
|
//var top_pos = parseInt(context.canvas.height - down_ticks_height - 10) - $('#watermark_image_'+graph_id)[0].height;
|
|
|
|
//var left_pos = 380;
|
|
|
|
context.drawImage(this, left_pos, top_pos);
|
|
|
|
},
|
|
|
|
false
|
|
|
|
);
|
2016-05-26 08:57:33 +02:00
|
|
|
}
|
|
|
|
|
2018-04-26 10:24:37 +02:00
|
|
|
//Ajusta la grafica pequenña con el desplazamiento del eje y
|
2016-05-26 08:57:33 +02:00
|
|
|
function adjust_left_width_canvas(adapter_id, adapted_id) {
|
2019-01-30 12:27:18 +01:00
|
|
|
var adapter_left_margin = $("#" + adapter_id + " .yAxis .tickLabel").width();
|
|
|
|
var adapted_pix = $("#" + adapted_id).width();
|
|
|
|
var new_adapted_width = adapted_pix - adapter_left_margin;
|
|
|
|
$("#" + adapted_id).width(new_adapted_width);
|
|
|
|
$("#" + adapted_id).css("margin-left", adapter_left_margin);
|
2016-05-26 08:57:33 +02:00
|
|
|
}
|
|
|
|
|
2018-04-26 10:24:37 +02:00
|
|
|
//Ajusta el ancho de la grafica pequeña con respecto a la grande
|
2017-11-14 18:44:29 +01:00
|
|
|
function update_left_width_canvas(graph_id) {
|
2019-01-30 12:27:18 +01:00
|
|
|
$("#overview_" + graph_id).width($("#" + graph_id).width());
|
|
|
|
$("#overview_" + graph_id).css(
|
|
|
|
"margin-left",
|
|
|
|
$("#" + graph_id + " .yAxis .tickLabel").width()
|
|
|
|
);
|
2017-11-14 18:44:29 +01:00
|
|
|
}
|
|
|
|
|
2016-05-26 08:57:33 +02:00
|
|
|
function check_adaptions(graph_id) {
|
2019-01-30 12:27:18 +01:00
|
|
|
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);
|
|
|
|
}
|
|
|
|
});
|
2016-05-26 08:57:33 +02:00
|
|
|
}
|
|
|
|
|
2019-12-05 17:41:44 +01:00
|
|
|
function number_format(number, force_integer, unit, short_data, divisor) {
|
|
|
|
divisor = typeof divisor !== "undefined" ? divisor : 1000;
|
2020-03-26 12:29:38 +01:00
|
|
|
var decimals = 2;
|
2019-12-05 17:41:44 +01:00
|
|
|
|
|
|
|
if (unit == "KB") {
|
2020-05-26 14:44:52 +02:00
|
|
|
return Math.round(number * decimals) + unit;
|
2019-12-05 17:41:44 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
// Set maximum decimal precision to 99 in case short_data is not set.
|
|
|
|
if (!short_data) {
|
|
|
|
short_data = 99;
|
|
|
|
}
|
|
|
|
|
2019-01-30 12:27:18 +01:00
|
|
|
if (force_integer) {
|
|
|
|
if (Math.round(number) != number) {
|
|
|
|
return "";
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
short_data++;
|
|
|
|
decimals = pad(1, short_data, 0);
|
|
|
|
number = Math.round(number * decimals) / decimals;
|
|
|
|
}
|
|
|
|
|
|
|
|
var shorts = ["", "K", "M", "G", "T", "P", "E", "Z", "Y"];
|
|
|
|
var pos = 0;
|
2019-12-05 17:41:44 +01:00
|
|
|
|
2020-10-01 15:29:54 +02:00
|
|
|
while (Math.abs(number) >= divisor) {
|
2019-12-05 17:41:44 +01:00
|
|
|
// As long as the number can be divided by 1000 or 1024.
|
|
|
|
pos++;
|
|
|
|
number = number / divisor;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (divisor) {
|
|
|
|
number = Math.round(number * decimals) / decimals;
|
2020-05-26 14:44:52 +02:00
|
|
|
} else {
|
|
|
|
number = Math.round(number * decimals);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (isNaN(number)) {
|
|
|
|
number = 0;
|
2019-01-30 12:27:18 +01:00
|
|
|
}
|
2018-05-10 08:43:09 +02:00
|
|
|
|
2019-01-30 12:27:18 +01:00
|
|
|
return number + " " + shorts[pos] + unit;
|
2016-05-26 08:57:33 +02:00
|
|
|
}
|
2018-02-28 14:33:22 +01:00
|
|
|
|
2018-05-10 08:43:09 +02:00
|
|
|
function pad(input, length, padding) {
|
2019-01-30 12:27:18 +01:00
|
|
|
var str = input + "";
|
|
|
|
return length <= str.length ? str : pad(str + padding, length, padding);
|
2018-02-28 14:33:22 +01:00
|
|
|
}
|
2018-05-10 08:43:09 +02:00
|
|
|
|
2017-03-22 11:30:41 +01:00
|
|
|
// Recalculate the threshold data depends on warning and critical
|
2019-01-30 12:27:18 +01:00
|
|
|
function axis_thresholded(
|
|
|
|
threshold_data,
|
|
|
|
y_min,
|
|
|
|
y_max,
|
|
|
|
red_threshold,
|
|
|
|
extremes,
|
|
|
|
red_up
|
|
|
|
) {
|
|
|
|
var y = {
|
|
|
|
min: 0,
|
|
|
|
max: 0
|
|
|
|
};
|
|
|
|
|
|
|
|
// Default values
|
|
|
|
var yaxis_resize = {
|
|
|
|
up: null,
|
|
|
|
normal_up: 0,
|
|
|
|
normal_down: 0,
|
|
|
|
down: null
|
|
|
|
};
|
|
|
|
// Resize the y axis to display all intervals
|
|
|
|
$.each(threshold_data, function() {
|
|
|
|
if (/_up/.test(this.id)) {
|
|
|
|
yaxis_resize["up"] = this.data[0][1];
|
|
|
|
}
|
|
|
|
if (/_down/.test(this.id)) {
|
|
|
|
if (/critical/.test(this.id)) {
|
|
|
|
yaxis_resize["down"] = red_threshold;
|
|
|
|
} else {
|
|
|
|
yaxis_resize["down"] = extremes[this.id];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (/_normal/.test(this.id)) {
|
|
|
|
var end;
|
|
|
|
if (/critical/.test(this.id)) {
|
|
|
|
end = red_up;
|
|
|
|
} else {
|
|
|
|
end = extremes[this.id + "_2"];
|
|
|
|
}
|
|
|
|
if (yaxis_resize["normal_up"] < end) yaxis_resize["normal_up"] = end;
|
|
|
|
if (yaxis_resize["normal_down"] > this.data[0][1])
|
|
|
|
yaxis_resize["normal_down"] = this.data[0][1];
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
// If you need to display a up or a down bar, display 10% of data height
|
|
|
|
var margin_up_or_down = (y_max - y_min) * 0.1;
|
|
|
|
|
|
|
|
// Calculate the new axis
|
|
|
|
y["max"] =
|
|
|
|
yaxis_resize["normal_up"] > y_max ? yaxis_resize["normal_up"] : y_max;
|
|
|
|
y["min"] =
|
|
|
|
yaxis_resize["normal_down"] > y_min ? yaxis_resize["normal_down"] : y_min;
|
|
|
|
if (yaxis_resize["up"] !== null) {
|
|
|
|
y["max"] =
|
|
|
|
yaxis_resize["up"] + margin_up_or_down < y_max
|
|
|
|
? y_max
|
|
|
|
: yaxis_resize["up"] + margin_up_or_down;
|
|
|
|
}
|
|
|
|
if (yaxis_resize["down"] !== null) {
|
|
|
|
y["min"] =
|
|
|
|
yaxis_resize["down"] - margin_up_or_down < y_min
|
|
|
|
? yaxis_resize["up"] + margin_up_or_down
|
|
|
|
: y_min;
|
|
|
|
}
|
|
|
|
|
|
|
|
return y;
|
2017-03-22 11:30:41 +01:00
|
|
|
}
|
2018-04-27 13:51:13 +02:00
|
|
|
|
2022-05-18 17:17:31 +02:00
|
|
|
//add threshold
|
2019-01-30 12:27:18 +01:00
|
|
|
function add_threshold(
|
|
|
|
data_base,
|
|
|
|
threshold_data,
|
|
|
|
y_min,
|
|
|
|
y_max,
|
|
|
|
red_threshold,
|
|
|
|
extremes,
|
|
|
|
red_up,
|
|
|
|
markins_graph
|
|
|
|
) {
|
|
|
|
var datas = new Array();
|
|
|
|
|
|
|
|
$.each(data_base, function() {
|
|
|
|
datas.push(this);
|
|
|
|
});
|
|
|
|
|
|
|
|
var threshold_array = [];
|
|
|
|
|
|
|
|
// Resize the threshold data
|
|
|
|
$.each(threshold_data, function(index, value) {
|
|
|
|
threshold_array[index] = [];
|
|
|
|
|
|
|
|
if (/_up/.test(this.id)) {
|
|
|
|
this.bars.barWidth = y_max - this.data[0][1];
|
|
|
|
|
|
|
|
if (/critical/.test(this.id)) {
|
|
|
|
threshold_array[index]["min"] = this.data[0][1];
|
|
|
|
threshold_array[index]["max"] = y_max;
|
|
|
|
threshold_array[index]["color"] = "red";
|
|
|
|
} else {
|
|
|
|
threshold_array[index]["min"] = this.data[0][1];
|
|
|
|
threshold_array[index]["max"] = y_max;
|
|
|
|
threshold_array[index]["color"] = "yellow";
|
|
|
|
}
|
|
|
|
|
|
|
|
if (y_min > this.data[0][1]) {
|
|
|
|
this.bars.barWidth = this.bars.barWidth - (y_min - this.data[0][1]);
|
|
|
|
this.data[0][1] = y_min;
|
|
|
|
}
|
|
|
|
}
|
2018-05-10 08:43:09 +02:00
|
|
|
|
2019-01-30 12:27:18 +01:00
|
|
|
if (/_down/.test(this.id)) {
|
|
|
|
var end;
|
|
|
|
if (/critical/.test(this.id)) {
|
|
|
|
end = red_threshold;
|
|
|
|
} else {
|
|
|
|
end = extremes[this.id];
|
|
|
|
}
|
|
|
|
|
|
|
|
this.bars.barWidth = end - y_min;
|
|
|
|
this.data[0][1] = y_min;
|
|
|
|
|
|
|
|
if (/critical/.test(this.id)) {
|
|
|
|
threshold_array[index]["min"] = this.data[0][1];
|
|
|
|
threshold_array[index]["max"] = this.bars.barWidth;
|
|
|
|
threshold_array[index]["color"] = "red";
|
|
|
|
} else {
|
|
|
|
threshold_array[index]["min"] = this.data[0][1];
|
|
|
|
threshold_array[index]["max"] = this.bars.barWidth;
|
|
|
|
threshold_array[index]["color"] = "yellow";
|
|
|
|
}
|
|
|
|
}
|
2018-05-10 08:43:09 +02:00
|
|
|
|
2019-01-30 12:27:18 +01:00
|
|
|
if (/_normal/.test(this.id)) {
|
|
|
|
var end;
|
|
|
|
if (/critical/.test(this.id)) {
|
|
|
|
end = red_up;
|
|
|
|
threshold_array[index]["min"] = this.data[0][1];
|
|
|
|
threshold_array[index]["max"] = end;
|
|
|
|
threshold_array[index]["color"] = "red";
|
|
|
|
} else {
|
|
|
|
var first = extremes[this.id + "_1"];
|
|
|
|
var second = extremes[this.id + "_2"];
|
|
|
|
if (first > second) {
|
|
|
|
end = first;
|
|
|
|
} else {
|
|
|
|
end = second;
|
|
|
|
}
|
|
|
|
threshold_array[index]["min"] = this.data[0][1];
|
|
|
|
threshold_array[index]["max"] = end;
|
|
|
|
threshold_array[index]["color"] = "yellow";
|
|
|
|
}
|
|
|
|
|
|
|
|
if (this.data[0][1] < y_min) {
|
|
|
|
this.bars.barWidth = end - y_min;
|
|
|
|
this.data[0][1] = y_min;
|
|
|
|
end = this.bars.barWidth + this.data[0][1];
|
|
|
|
|
|
|
|
if (/critical/.test(this.id)) {
|
|
|
|
threshold_array[index]["min"] = this.data[0][1];
|
|
|
|
threshold_array[index]["max"] = this.data[0][1] + this.bars.barWidth;
|
|
|
|
threshold_array[index]["color"] = "red";
|
|
|
|
} else {
|
|
|
|
threshold_array[index]["min"] = this.data[0][1];
|
|
|
|
threshold_array[index]["max"] = this.data[0][1] + this.bars.barWidth;
|
|
|
|
threshold_array[index]["color"] = "yellow";
|
|
|
|
}
|
|
|
|
}
|
2018-05-10 08:43:09 +02:00
|
|
|
|
2019-01-30 12:27:18 +01:00
|
|
|
if (end > y_max) {
|
|
|
|
this.bars.barWidth = y_max - this.data[0][1];
|
|
|
|
|
|
|
|
if (/critical/.test(this.id)) {
|
|
|
|
threshold_array[index]["min"] = this.data[0][1];
|
|
|
|
threshold_array[index]["max"] = this.data[0][1] + this.bars.barWidth;
|
|
|
|
threshold_array[index]["color"] = "red";
|
|
|
|
} else {
|
|
|
|
threshold_array[index]["min"] = this.data[0][1];
|
|
|
|
threshold_array[index]["max"] = this.data[0][1] + this.bars.barWidth;
|
|
|
|
threshold_array[index]["color"] = "yellow";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (markins_graph && this.bars.barWidth > 0) {
|
|
|
|
datas.push(this);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2022-05-18 17:17:31 +02:00
|
|
|
var extreme_threshold_array = [];
|
2019-01-30 12:27:18 +01:00
|
|
|
var i = 0;
|
|
|
|
var flag = true;
|
|
|
|
|
|
|
|
$.each(threshold_array, function(index, value) {
|
|
|
|
flag = true;
|
2022-05-18 17:17:31 +02:00
|
|
|
extreme_threshold_array[i] = {
|
2019-01-30 12:27:18 +01:00
|
|
|
below: value["max"],
|
|
|
|
color: value["color"]
|
|
|
|
};
|
|
|
|
i++;
|
|
|
|
$.each(threshold_array, function(i, v) {
|
|
|
|
if (value["min"] == v["max"]) {
|
|
|
|
return (flag = false);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
if (flag) {
|
2022-05-18 17:17:31 +02:00
|
|
|
extreme_threshold_array[i] = {
|
2019-01-30 12:27:18 +01:00
|
|
|
below: value["min"],
|
|
|
|
color: datas[0].color
|
|
|
|
};
|
|
|
|
i++;
|
|
|
|
}
|
|
|
|
});
|
2018-04-27 13:51:13 +02:00
|
|
|
|
2022-05-18 17:17:31 +02:00
|
|
|
datas[0].threshold = extreme_threshold_array;
|
2018-05-10 08:43:09 +02:00
|
|
|
|
2019-01-30 12:27:18 +01:00
|
|
|
return datas;
|
2016-05-26 08:57:33 +02:00
|
|
|
}
|
2016-06-13 17:17:54 +02:00
|
|
|
|
2019-01-30 12:27:18 +01:00
|
|
|
function reduceText(text, maxLength) {
|
|
|
|
if (!text) return text;
|
|
|
|
if (text.length <= maxLength) return text;
|
|
|
|
var firstSlideEnd = parseInt((maxLength - 3) / 1.6);
|
|
|
|
var str_cut = text.substr(0, firstSlideEnd);
|
2022-01-10 10:22:59 +01:00
|
|
|
//return str_cut + "...<br>" + text.substr(-firstSlideEnd - 3);
|
|
|
|
return str_cut + "..." + text.substr(-firstSlideEnd - 3);
|
2016-06-13 17:17:54 +02:00
|
|
|
}
|