Now the boolean charts is showed as digital signal charts (only with dinamic flot charts engine)

(cherry picked from commit 3d014c6ab5)

Conflicts:
	pandora_console/include/graphs/flot/pandora.flot.js
	pandora_console/include/graphs/functions_flot.php
This commit is contained in:
mdtrooper 2015-08-25 13:00:46 +02:00
parent 4a30988146
commit 1577621b5b
4 changed files with 1275 additions and 1443 deletions

View File

@ -3223,6 +3223,8 @@ function grafico_modulo_boolean_data ($agent_module_id, $period, $show_events,
$series_type['unknown'.$series_suffix] = 'area';
}
$series_type['sum' . $series_suffix] = 'boolean';
//Boolean graph doesn't have min!!!
/*if (!$avg_only) {
$chart[$timestamp]['min'.$series_suffix] = 0;
@ -3352,7 +3354,7 @@ function grafico_modulo_boolean ($agent_module_id, $period, $show_events,
$series_suffix_str = '';
if ($compare !== false) {
$series_suffix = '2';
$series_suffix_str = ' ('.__('Previous').')';
$series_suffix_str = ' (' . __('Previous') . ')';
// Build the data of the previous period
grafico_modulo_boolean_data ($agent_module_id, $period, $show_events,
$unit_name, $show_alerts, $avg_only, $date-$period, $series_suffix,
@ -3375,18 +3377,19 @@ function grafico_modulo_boolean ($agent_module_id, $period, $show_events,
$series_type_prev = $series_type;
$color_prev = $color;
foreach ($color_prev as $k => $col) {
$color_prev[$k]['color'] = '#'.get_complementary_rgb($color_prev[$k]['color']);
$color_prev[$k]['color'] = '#' . get_complementary_rgb($color_prev[$k]['color']);
}
break;
}
}
grafico_modulo_boolean_data ($agent_module_id, $period, $show_events,
$unit_name, $show_alerts, $avg_only, $date, '', '', $show_unknown);
if ($compare === 'overlapped') {
$i = 0;
foreach ($chart as $k=>$v) {
$chart[$k] = array_merge($v,$chart_prev[$i]);
foreach($chart as $k => $v) {
$chart[$k] = array_merge($v, $chart_prev[$i]);
$i++;
}
@ -3398,8 +3401,10 @@ function grafico_modulo_boolean ($agent_module_id, $period, $show_events,
$flash_chart = false;
}
$water_mark = array('file' => $config['homedir'] . "/images/logo_vertical_water.png",
'url' => ui_get_full_url("/images/logo_vertical_water.png", false, false, false));
$water_mark = array(
'file' => $config['homedir'] . "/images/logo_vertical_water.png",
'url' => ui_get_full_url("/images/logo_vertical_water.png",
false, false, false));
if ($config['type_module_charts'] === 'area') {
if ($compare === 'separated') {

View File

@ -568,7 +568,7 @@ function pandoraFlotArea(graph_id, values, labels, labels_long, legend,
alertsz[alert_ids[i]] = v;
});
switch(type) {
switch (type) {
case 'line_simple':
stacked = null;
filled = false;
@ -611,16 +611,26 @@ function pandoraFlotArea(graph_id, values, labels, labels_long, legend,
line_show = true;
points_show = false;
filled = true;
steps_chart = false;
break;
case 'line':
default:
line_show = true;
points_show = false;
filled = false;
steps_chart = false;
break;
case 'points':
line_show = false;
points_show = true;
filled = false;
steps_chart = false
break;
case 'boolean':
line_show = true;
points_show = false;
filled = false;
steps_chart = true;
break;
}
@ -653,10 +663,10 @@ function pandoraFlotArea(graph_id, values, labels, labels_long, legend,
//~ ];
lineWidht = $('#hidden-lineWidhtGraph');
if (typeof(lineWidht[0])=='undefined'){
if (typeof(lineWidht[0])=='undefined') {
WidhtLine = 1;
}
else{
else {
WidhtLine = lineWidht[0].value;
}
@ -667,13 +677,15 @@ function pandoraFlotArea(graph_id, values, labels, labels_long, legend,
label: legend[i],
color: serie_color,
//threshold: [{ below: 80, color: "rgb(200, 20, 30)" } , { below: 65, color: "rgb(30, 200, 30)" }, { below: 50, color: "rgb(30, 200, 30)" }],
lines: { show: line_show,
lines: {
show: line_show,
fill: filled,
fillColor: {
colors: [ { opacity: 0.9 }, { opacity: 0.9 } ]
},
lineWidth: WidhtLine,
steps: false },
steps: steps_chart
},
points: { show: points_show }
});
@ -1023,183 +1035,6 @@ function pandoraFlotArea(graph_id, values, labels, labels_long, legend,
//return '<div style=color:#000;font-size:'+font_size+'pt><input type="checkbox" id="' + graph_id + '_' + item.id +'" checked="checked" class="check_serie_'+graph_id+'">'+v+'</div>';
}
// Used to export the graph data to a file.
// Uses plot, labels and labels_long as scope variables.
function exportData (options) {
options = options || {};
// Options
var type = options.type || 'csv';
type = type.toLowerCase().trim();
var graphData,
dataObject,
dataObjects = plot.getData(),
result = [];
// Throw errors
var retrieveDataOject = function (dataObjects) {
var result;
if (typeof dataObjects === 'undefined')
throw new Error('Empty parameter');
// Try to retrieve the avg set (not 100% reliable, I know)
if (dataObjects.length == 1) {
result = dataObjects.shift();
}
if (dataObjects.length > 1) {
dataObjects.forEach(function (element) {
if (/^Avg.:/i.test(element.label))
result = element;
});
// If the avg set is missing, retrieve the first set
if (typeof result === 'undefined')
result = dataObjects.shift();
}
if (typeof result === 'undefined')
throw new Error('Empty result');
return result;
}
// Throw errors
var processDataObject = function (dataObject) {
var result;
if (typeof dataObject === 'undefined')
throw new Error('Empty parameter');
if (typeof dataObject.data === 'undefined'
|| !(dataObject.data instanceof Array))
throw new Error('Object malformed');
/* {
* head: [<column>,<column>,...,<column>],
* data: [
* [<data>,<data>,...,<data>],
* [<data>,<data>,...,<data>],
* ...,
* [<data>,<data>,...,<data>],
* ]
* }
*/
if (type === 'csv') {
result = {
head: ['date', 'value'],
data: []
};
dataObject.data.forEach(function (item, index) {
var date = '', value = item[1];
// Long labels are preferred
if (typeof labels_long[index] !== 'undefined')
date = labels_long[index];
else if (typeof labels[index] !== 'undefined')
date = labels[index];
result.data.push([date, value]);
});
}
/* [
* {
* 'date': <date>,
* 'value': <value>
* }
* ],
* [
* {
* 'date': <date>,
* 'value': <value>
* }
* ],
* ...,
* [
* {
* 'date': <date>,
* 'value': <value>
* }
* ]
*/
else if (type === 'json') {
result = [];
dataObject.data.forEach(function (item, index) {
var date = '', value = item[1];
// Long labels are preferred
if (typeof labels_long[index] !== 'undefined')
date = labels_long[index];
else if (typeof labels[index] !== 'undefined')
date = labels[index];
result.push({
'date': date,
'value': value
});
});
}
if (typeof result === 'undefined')
throw new Error('Empty result');
return result;
}
try {
dataObject = retrieveDataOject(dataObjects);
graphData = processDataObject(dataObject);
// Transform the object data into a string
// cause PHP has limitations in the number
// of POST params received.
var graphDataStr = JSON.stringify(graphData);
// Build form
var $form = $('<form></form>'),
$dataInput = $('<input>'),
$typeInput = $('<input>'),
$separatorInput = $('<input>'),
$excelInput = $('<input>');
$dataInput
.prop('name', 'data')
.prop('type', 'text')
.prop('value', graphDataStr);
$typeInput
.prop('name', 'type')
.prop('type', 'text')
.prop('value', type);
$separatorInput
.prop('name', 'separator')
.prop('type', 'text')
.prop('value', ';');
$excelInput
.prop('name', 'excel_encoding')
.prop('type', 'text')
.prop('value', false);
$form
.prop('method', 'POST')
.prop('action', homeurl + '/include/graphs/export_data.php')
.append($dataInput, $typeInput, $separatorInput, $excelInput)
.hide()
// Firefox made me write into the DOM for this :(
.appendTo('body')
.submit();
}
catch (e) {
alert('There was an error exporting the data');
console.log(e);
}
}
// Prepared to turn series with a checkbox
//~ $('.check_serie_'+graph_id).click(function() {
//~ // Format of the id is graph_3905jf93f03_serie_id
@ -1217,14 +1052,6 @@ function pandoraFlotArea(graph_id, values, labels, labels_long, legend,
$('#overview_' + graph_id).css('visibility','hidden');
});
$('#menu_export_csv_' + graph_id).click(function() {
exportData({ type: 'csv' });
});
$('#menu_export_json_' + graph_id).click(function() {
exportData({ type: 'json' });
});
$('#menu_threshold_' + graph_id).click(function() {
datas = new Array();
@ -1259,7 +1086,7 @@ function pandoraFlotArea(graph_id, values, labels, labels_long, legend,
}));
$('#menu_cancelzoom_' + graph_id)
.attr('src', homeurl + '/images/zoom_cross_grey.disabled.png');
.attr('src', homeurl + '/images/zoom_cross.disabled.png');
overview.clearSelection();
currentRanges = null;
});

View File

@ -264,7 +264,7 @@ function flot_area_graph($chart_data, $width, $height, $color, $legend,
}
}
foreach($chart_data as $label => $values) {
foreach ($chart_data as $label => $values) {
$labels[] = io_safe_output($label);
foreach($values as $key => $value) {
@ -328,7 +328,7 @@ function flot_area_graph($chart_data, $width, $height, $color, $legend,
$extra_width = (int)($width / 3);
$return .= "<div id='extra_$graph_id' style='font-size: ".$font_size."pt; display:none; position:absolute; overflow: auto; max-height: ".($height+50)."px; width: ".$extra_width."px; background:#fff; padding: 2px 2px 2px 2px; border: solid #000 1px;'></div>";
$return .= "<div id='extra_$graph_id' style='font-size: " . $font_size . "pt; display:none; position:absolute; overflow: auto; max-height: ".($height+50)."px; width: ".$extra_width."px; background:#fff; padding: 2px 2px 2px 2px; border: solid #000 1px;'></div>";
// Process extra data
$events = array();