change xasis to time

This commit is contained in:
daniel 2018-02-02 12:25:23 +01:00
parent d79bd6973f
commit 63e5d23288
1 changed files with 73 additions and 22 deletions

View File

@ -868,7 +868,7 @@ function pandoraFlotArea(graph_id, values, labels, labels_long, legend,
yellow_up, red_up, yellow_inverse, red_inverse, yellow_up, red_up, yellow_inverse, red_inverse,
series_suffix_str, dashboard, vconsole, xaxisname,background_color,legend_color, series_suffix_str, dashboard, vconsole, xaxisname,background_color,legend_color,
short_data) { short_data) {
var threshold = true; var threshold = true;
var thresholded = false; var thresholded = false;
font = font.split("/").pop().split(".").shift(); font = font.split("/").pop().split(".").shift();
@ -877,12 +877,12 @@ function pandoraFlotArea(graph_id, values, labels, labels_long, legend,
serie_types = serie_types.split(separator); serie_types = serie_types.split(separator);
labels_long = labels_long.split(separator); labels_long = labels_long.split(separator);
labels = labels.split(separator); labels = labels.split(separator);
// XXX 1827 //XXX 1827
/* Translate datetime to utimestamp -> avoid convert datetime in server better... //Translate datetime to utimestamp -> avoid convert datetime in server better...
$.each(labels, function (i,v) { $.each(labels, function (i,v) {
labels[i] = new Date(labels[i]).getTime(); labels[i] = new Date(labels[i]).getTime();
}); });
*/
legend = legend.split(separator); legend = legend.split(separator);
events = events.split(separator); events = events.split(separator);
event_ids = event_ids.split(separator); event_ids = event_ids.split(separator);
@ -932,21 +932,20 @@ function pandoraFlotArea(graph_id, values, labels, labels_long, legend,
for (i = 0; i < values.length; i++) { for (i = 0; i < values.length; i++) {
var serie = values[i].split(separator); var serie = values[i].split(separator);
var aux = new Array(); var aux = new Array();
$.each(serie, function(i, v) { $.each(serie, function(i, v) {
if(v < 0){ if(v < 0){
if(min_check > parseFloat(v)){ if(min_check > parseFloat(v)){
min_check = v; min_check = v;
} }
} }
aux.push([i, v]);
// XXX 1827 // XXX 1827
/* //aux.push([i, v]);
aux.push([labels[i], v]); aux.push([labels[i], v]);
*/
}); });
//XXX
var time_format_y = labels[labels.length - 1] - labels[0];
switch (serie_types[i]) { switch (serie_types[i]) {
case 'area': case 'area':
line_show = true; line_show = true;
@ -1028,6 +1027,8 @@ function pandoraFlotArea(graph_id, values, labels, labels_long, legend,
// Prepared to turn series with a checkbox // Prepared to turn series with a checkbox
// showed[i] = true; // showed[i] = true;
} }
console.log(data_base);
max_x = data_base[0]['data'][data_base[0]['data'].length -1][0];
if(min_check != 0){ if(min_check != 0){
min_check = min_check -5; min_check = min_check -5;
@ -1579,17 +1580,19 @@ function pandoraFlotArea(graph_id, values, labels, labels_long, legend,
color: legend_color color: legend_color
}, },
xaxes: [{ xaxes: [{
/*
axisLabelFontSizePixels: font_size, axisLabelFontSizePixels: font_size,
axisLabelUseCanvas: false, axisLabelUseCanvas: false,
tickFormatter: xFormatter, tickFormatter: xFormatter,
labelHeight: 50, labelHeight: 50,
color: '', color: '',
font: font, font: font,
*/
// XXX 1827 // XXX 1827
/* axisLabelUseCanvas: false,
axisLabelFontSizePixels: font_size,
mode: "time", mode: "time",
timeformat: "%Y/%m/%d %H:%M:%S", tickFormatter: xFormatter,
*/
}], }],
yaxes: [{ yaxes: [{
tickFormatter: yFormatter, tickFormatter: yFormatter,
@ -1674,7 +1677,10 @@ function pandoraFlotArea(graph_id, values, labels, labels_long, legend,
if (menu == 0) { if (menu == 0) {
return; return;
} }
//XXX
dataInSelection = ranges.xaxis.to - ranges.xaxis.from; dataInSelection = ranges.xaxis.to - ranges.xaxis.from;
//time_format_y = dataInSelection;
dataInPlot = plot.getData()[0].data.length; dataInPlot = plot.getData()[0].data.length;
factor = dataInSelection / dataInPlot; factor = dataInSelection / dataInPlot;
@ -1686,7 +1692,8 @@ function pandoraFlotArea(graph_id, values, labels, labels_long, legend,
xaxis: { min: ranges.xaxis.from, max: ranges.xaxis.to}, xaxis: { min: ranges.xaxis.from, max: ranges.xaxis.to},
xaxes: [ { xaxes: [ {
tickFormatter: xFormatter, tickFormatter: xFormatter,
minTickSize: new_steps, //XXX
//minTickSize: new_steps,
color: '' color: ''
} ], } ],
legend: { show: false } legend: { show: false }
@ -1931,11 +1938,50 @@ function pandoraFlotArea(graph_id, values, labels, labels_long, legend,
// Format functions // Format functions
function xFormatter(v, axis) { function xFormatter(v, axis) {
if (labels[v] == undefined) { //XXX
return ''; /*
if ($period <= SECONDS_6HOURS) {
$time_format = 'H:i:s';
}
elseif ($period < SECONDS_1DAY) {
$time_format = 'H:i';
}
elseif ($period < SECONDS_15DAYS) {
$time_format = "M \nd H:i";
}
elseif ($period < SECONDS_1MONTH) {
$time_format = "M \nd H\h";
}
elseif ($period < SECONDS_6MONTHS) {
$time_format = "M \nd H\h";
}
else {
$time_format = "Y M \nd H\h";
}
*/
var d = new Date(v);
var result_date_format = 0;
if(time_format_y > 86400000){ //DAY
result_date_format =
d.getDate() + "/" +
(d.getMonth() + 1) + "/" +
d.getFullYear() + "\n" +
d.getHours() + ":" +
d.getMinutes() + ":" +
d.getSeconds(); //+ ":" + d.getMilliseconds();
} }
extra_css = ''; else{
return '<div class='+font+' style="font-size:'+font_size+'pt; margin-top:15px;'+extra_css+'">'+labels[v]+'</div>'; result_date_format =
d.getHours() + ":" +
d.getMinutes() + ":" +
d.getSeconds(); //+ ":" + d.getMilliseconds();
}
//extra_css = '';
return '<div class='+font+' style="transform: rotate(-15deg); -ms-transform:rotate(-15deg); -moz-transform:rotate(-15deg); -webkit-transform:rotate(-15deg); -o-transform:rotate(-15deg); font-size:'+font_size+'pt; margin-top:15px;">'+result_date_format+'</div>';
} }
function yFormatter(v, axis) { function yFormatter(v, axis) {
@ -2005,11 +2051,11 @@ function pandoraFlotArea(graph_id, values, labels, labels_long, legend,
thresholded = false; thresholded = false;
} }
else { else {
var max_draw = plot.getAxes().yaxis.datamax; var max_draw = plot.getAxes().yaxis.datamax;
// Recalculate the y axis // Recalculate the y axis
var y_recal = axis_thresholded(threshold_data, plot.getAxes().yaxis.min, plot.getAxes().yaxis.max, var y_recal = axis_thresholded(threshold_data, plot.getAxes().yaxis.min, plot.getAxes().yaxis.max,
red_threshold, extremes, red_up); red_threshold, extremes, red_up);
plot = $.plot($('#' + graph_id), data_base, plot = $.plot($('#' + graph_id), data_base,
$.extend(true, {}, options, { $.extend(true, {}, options, {
yaxis: { yaxis: {
@ -2017,16 +2063,19 @@ function pandoraFlotArea(graph_id, values, labels, labels_long, legend,
min: y_recal.min min: y_recal.min
}, },
xaxis: { xaxis: {
mode:"time",
min: plot.getAxes().xaxis.min, min: plot.getAxes().xaxis.min,
max: plot.getAxes().xaxis.max max: plot.getAxes().xaxis.max
} }
})); }));
datas = add_threshold (data_base, threshold_data, plot.getAxes().yaxis.min, plot.getAxes().yaxis.max, datas = add_threshold (data_base, threshold_data, plot.getAxes().yaxis.min, plot.getAxes().yaxis.max,
red_threshold, extremes, red_up); red_threshold, extremes, red_up);
thresholded = true; thresholded = true;
} }
plot.setData(datas); plot.setData(datas);
plot.draw(); plot.draw();
@ -2037,10 +2086,11 @@ function pandoraFlotArea(graph_id, values, labels, labels_long, legend,
// cancel the zooming // cancel the zooming
plot = $.plot($('#' + graph_id), data_base, plot = $.plot($('#' + graph_id), data_base,
$.extend(true, {}, options, { $.extend(true, {}, options, {
//XXX
xaxis: {max: max_x }, xaxis: {max: max_x },
legend: { show: false } legend: { show: false }
})); }));
$('#menu_cancelzoom_' + graph_id) $('#menu_cancelzoom_' + graph_id)
.attr('src', homeurl + '/images/zoom_cross.disabled.png'); .attr('src', homeurl + '/images/zoom_cross.disabled.png');
overview.clearSelection(); overview.clearSelection();
@ -2300,7 +2350,7 @@ function add_threshold (data_base, threshold_data, y_min, y_max,
if (/_down/.test(this.id)){ if (/_down/.test(this.id)){
var end; var end;
if (/critical/.test(this.id)) { if (/critical/.test(this.id)) {
end = red_threshold; end = red_threshold;
} else { } else {
end = extremes[this.id]; end = extremes[this.id];
} }
@ -2327,6 +2377,7 @@ function add_threshold (data_base, threshold_data, y_min, y_max,
}); });
return datas; return datas;
} }
function reduceText (text, maxLength) { function reduceText (text, maxLength) {