Fixed problems with visual maps in dashboards view. Gitlab: #374

This commit is contained in:
m-lopez-f 2017-02-28 10:49:12 +01:00
parent 4d89b6496f
commit 0dd770a551
3 changed files with 176 additions and 383 deletions

View File

@ -882,72 +882,62 @@ else{
$only_image = !$graph_javascript || $isExternalLink;
if ($layoutData['id_custom_graph'] != 0) {
// Show only avg on the visual console
if(get_parameter('action') == 'edit'){
if($width == 0 || $height == 0){
$img = '<img src="images/console/signes/custom_graph.png" style="width:300px;height:180px;'.$imgpos.'">';
if (get_parameter('action') == 'edit') {
if($width == 0 || $height == 0) {
$img = '<img src="images/console/signes/custom_graph.png" style="width:300px;height:180px;'.$imgpos.'">';
}
else {
$img = '<img src="images/console/signes/custom_graph.png" style="width:'.$width.'px;height:'.$height.'px;'.$imgpos.'">';
}
}
else {
if ($width == 0 || $height == 0) {
if ($layoutData['label_position']=='left') {
$img = '<div style="float:right;height:'.$himg.'px;">'.custom_graphs_print(
$layoutData['id_custom_graph'], 180, 300,
$period, null, true, 0, $only_image, $layoutData['image'],
array(), '', array(), array(), true,
false, false, true, 1, false, true).'</div>';
}
else{
$img = '<img src="images/console/signes/custom_graph.png" style="width:'.$width.'px;height:'.$height.'px;'.$imgpos.'">';
}
}
else{
if($width == 0 || $height == 0){
if($layoutData['label_position']=='left'){
$img = '<div style="float:right;height:'.$himg.'px;">'.custom_graphs_print(
$layoutData['id_custom_graph'], 180, 300,
$period, null, true, 0, false, $layoutData['image'],
array(), '', array(), array(), true,
false, false, true, 1, false, true).'</div>';
}
else if($layoutData['label_position']=='right'){
$img = '<div style="float:left;height:'.$himg.'px;">'.custom_graphs_print(
$layoutData['id_custom_graph'], 180, 300,
$period, null, true, 0, false, $layoutData['image'],
array(), '', array(), array(), true,
false, false, true, 1, false, true).'</div>';
}
else{
$img = custom_graphs_print(
$layoutData['id_custom_graph'], 180, 300,
$period, null, true, 0, false, $layoutData['image'],
array(), '', array(), array(), true,
false, false, true, 1, false, true);
}
}
else{
if($layoutData['label_position']=='left'){
$img = '<div style="float:right;height:'.$himg.'px;">'.custom_graphs_print(
$layoutData['id_custom_graph'],$height,$width,
$period, null, true, 0, false, $layoutData['image'],
array(), '', array(), array(), true,
false, false, true, 1, false, true).'</div>';
}
else if($layoutData['label_position']=='right'){
elseif ($layoutData['label_position']=='right') {
$img = '<div style="float:left;height:'.$himg.'px;">'.custom_graphs_print(
$layoutData['id_custom_graph'],$height,$width,
$period, null, true, 0, false, $layoutData['image'],
array(), '', array(), array(), true,
false, false, true, 1, false, true).'</div>';
$layoutData['id_custom_graph'], 180, 300,
$period, null, true, 0, $only_image, $layoutData['image'],
array(), '', array(), array(), true,
false, false, true, 1, false, true).'</div>';
}
else {
$img = custom_graphs_print(
$layoutData['id_custom_graph'], 180, 300,
$period, null, true, 0, $only_image, $layoutData['image'],
array(), '', array(), array(), true,
false, false, true, 1, false, true);
}
}
else{
$img = custom_graphs_print(
$layoutData['id_custom_graph'],$height,$width,
$period, null, true, 0, false, $layoutData['image'],
array(), '', array(), array(), true,
false, false, true, 1, false, true);
else {
if ($layoutData['label_position']=='left') {
$img = '<div style="float:right;height:'.$himg.'px;">'.custom_graphs_print(
$layoutData['id_custom_graph'], $height, $width,
$period, null, true, 0, $only_image, $layoutData['image'],
array(), '', array(), array(), true,
false, false, true, 1, false, true).'</div>';
}
elseif($layoutData['label_position']=='right') {
$img = '<div style="float:left;height:'.$himg.'px;">'.custom_graphs_print(
$layoutData['id_custom_graph'], $height, $width,
$period, null, true, 0, $only_image, $layoutData['image'],
array(), '', array(), array(), true,
false, false, true, 1, false, true).'</div>';
}
else {
$img = custom_graphs_print(
$layoutData['id_custom_graph'], $height, $width,
$period, null, true, 0, $only_image, $layoutData['image'],
array(), '', array(), array(), true,
false, false, true, 1, false, true);
}
}
}
}
}
else {
if ($isExternalLink)
@ -955,65 +945,71 @@ else{
else
$homeurl = '';
if(get_parameter('action') == 'edit'){
if (get_parameter('action') == 'edit') {
if($width == 0 || $height == 0){
$img = '<img src="images/console/signes/module_graph.png" style="width:300px;height:180px;'.$imgpos.'">';
}
else{
$img = '<img src="images/console/signes/module_graph.png" style="width:'.$width.'px;height:'.$height.'px;'.$imgpos.'">';
}
}
else{
if($width == 0 || $height == 0){
if($layoutData['label_position']=='left'){
$img = '<div style="float:right;height:'.$himg.'px;">'.grafico_modulo_sparse($id_module, $period, 0,300,180,
'',null,
false, 1, false, 0, '', 0, 0, true, false, '', 1, false,
'', false, false, false, $layoutData['image'], null, true, false,$type_graph).'</div>';
}
else if($layoutData['label_position']=='right'){
$img = '<div style="float:left;height:'.$himg.'px;">'.grafico_modulo_sparse($id_module, $period, 0,300,180,
'',null,
false, 1, false, 0, '', 0, 0, true, false, '', 1, false,
'', false, false, false, $layoutData['image'], null, true, false,$type_graph).'</div>';
}
else{
$img = grafico_modulo_sparse($id_module, $period, 0,300,180,
'',null,
false, 1, false, 0, '', 0, 0, true, false, '', 1, false,
'', false, false, false, $layoutData['image'], null, true, false,$type_graph);
}
$img = '<img src="images/console/signes/module_graph.png" style="width:300px;height:180px;'.$imgpos.'">';
}
else{
$img = '<img src="images/console/signes/module_graph.png" style="width:'.$width.'px;height:'.$height.'px;'.$imgpos.'">';
}
}
else {
if ($width == 0 || $height == 0) {
if($layoutData['label_position']=='left'){
$img = '<div style="float:right;height:'.$himg.'px;">'.grafico_modulo_sparse($id_module, $period, 0,$width,$height,
'',null,
false, 1, false, 0, '', 0, 0, true, false, '', 1, false,
'', false, false, false, $layoutData['image'], null, true, false,$type_graph).'</div>';
}
else if($layoutData['label_position']=='right'){
$img = '<div style="float:left;height:'.$himg.'px;">'.grafico_modulo_sparse($id_module, $period, 0,$width,$height,
'',null,
false, 1, false, 0, '', 0, 0, true, false, '', 1, false,
'', false, false, false, $layoutData['image'], null, true, false,$type_graph).'</div>';
if ($layoutData['label_position']=='left') {
$img = '<div style="float:right;height:'.$himg.'px;">'.
grafico_modulo_sparse($id_module, $period,
0, 300, 180, '',null, false, 1, false, 0,
'', 0, 0, true, $only_image, '', 1, false, '',
false, false, false, $layoutData['image'],
null, true, false, $type_graph) . '</div>';
}
else{
$img = grafico_modulo_sparse($id_module, $period, 0,$width,$height,
elseif($layoutData['label_position']=='right') {
$img = '<div style="float:left;height:'.$himg.'px;">' .
grafico_modulo_sparse($id_module,
$period, 0, 300, 180, '',null, false,
1, false, 0, '', 0, 0, true, $only_image, '',
1, false, '', false, false, false,
$layoutData['image'], null, true,
false, $type_graph) . '</div>';
}
else {
$img = grafico_modulo_sparse($id_module, $period, 0,300,180,
'',null,
false, 1, false, 0, '', 0, 0, true, false, '', 1, false,
false, 1, false, 0, '', 0, 0, true, $only_image, '', 1, false,
'', false, false, false, $layoutData['image'], null, true, false,$type_graph);
}
}
else{
if ($layoutData['label_position']=='left') {
$img = '<div style="float:right;height:'.$himg.'px;">' .
grafico_modulo_sparse($id_module, $period,
0, $width, $height, '', null, false, 1,
false, 0, '', 0, 0, true, $only_image, '',
1, false, '', false, false, false,
$layoutData['image'], null, true,
false, $type_graph) . '</div>';
}
elseif ($layoutData['label_position']=='right') {
$img = '<div style="float:left;height:'.$himg.'px;">' .
grafico_modulo_sparse($id_module, $period,
0, $width, $height, '', null, false, 1,
false, 0, '', 0, 0, true, $only_image,
'', 1, false, '', false, false, false,
$layoutData['image'], null, true,
false, $type_graph) . '</div>';
}
else {
$img = grafico_modulo_sparse($id_module,
$period, 0, $width, $height, '', null,
false, 1, false, 0, '', 0, 0, true,
$only_image, '', 1, false, '', false,
false, false, $layoutData['image'],
null, true, false, $type_graph);
}
}
}
}
}
//Restore db connection
if ($layoutData['id_metaconsole'] != 0) {
@ -1081,9 +1077,7 @@ else{
switch ($type) {
case BOX_ITEM:
if($width == 0 || $width == 0){
if ($width == 0 || $width == 0) {
$style = "";
$style .= "width: 300px; ";
$style .= "height: 180px; ";
@ -1093,29 +1087,28 @@ else{
$style .= "background-color: " . $fill_color . "; ";
echo "<div style='" . $style . "'></div>";
}
else{
if (!empty($proportion)){
$style = "";
$style .= "width: " . ($width * $proportion['proportion_width']) . "px; ";
$style .= "height: " . ($height * $proportion['proportion_height']) . "px; ";
$style .= "border-style: solid; ";
$style .= "border-width: " . $border_width . "px; ";
$style .= "border-color: " . $border_color . "; ";
$style .= "background-color: " . $fill_color . "; ";
echo "<div style='" . $style . "'></div>";
}
else{
$style = "";
$style .= "width: " . $width . "px; ";
$style .= "height: " . $height . "px; ";
$style .= "border-style: solid; ";
$style .= "border-width: " . $border_width . "px; ";
$style .= "border-color: " . $border_color . "; ";
$style .= "background-color: " . $fill_color . "; ";
echo "<div style='" . $style . "'></div>";
}
else {
if (!empty($proportion)) {
$style = "";
$style .= "width: " . ($width * $proportion['proportion_width']) . "px; ";
$style .= "height: " . ($height * $proportion['proportion_height']) . "px; ";
$style .= "border-style: solid; ";
$style .= "border-width: " . $border_width . "px; ";
$style .= "border-color: " . $border_color . "; ";
$style .= "background-color: " . $fill_color . "; ";
echo "<div style='" . $style . "'></div>";
}
else {
$style = "";
$style .= "width: " . $width . "px; ";
$style .= "height: " . $height . "px; ";
$style .= "border-style: solid; ";
$style .= "border-width: " . $border_width . "px; ";
$style .= "border-color: " . $border_color . "; ";
$style .= "background-color: " . $fill_color . "; ";
echo "<div style='" . $style . "'></div>";
}
}
break;
case STATIC_GRAPH:
case GROUP_ITEM:
@ -1351,14 +1344,16 @@ else{
break;
case MODULE_GRAPH:
if($layoutData['label_position']=='up'){
if ($layoutData['label_position']=='up') {
echo io_safe_output($text);
}
echo $img;
if($layoutData['label_position']=='down'){
echo io_safe_output($text);
}
else if($layoutData['label_position']=='left' || $layoutData['label_position']=='right'){
if ($layoutData['label_position']=='down') {
echo io_safe_output($text);
}
elseif($layoutData['label_position']=='left' || $layoutData['label_position']=='right') {
echo io_safe_output($text);
}
break;
@ -2390,8 +2385,8 @@ function visual_map_print_visual_map ($id_layout, $show_links = true,
//Fixed to wait the load of images.
$(window).load(function () {
draw_lines(lines, 'background_'+id_layout);
draw_user_lines_read('background_'+id_layout);
draw_lines(lines, 'background_' + id_layout);
draw_user_lines_read('background_' + id_layout);
//center_labels();
});
/* ]]> */
@ -2433,20 +2428,20 @@ function visual_map_print_visual_map ($id_layout, $show_links = true,
$backgroundImage =
'/include/Image/image_functions.php?getFile=1&thumb=1&thumb_size=' . $mapWidth . 'x' . $mapHeight . '&file=' .
$config['homeurl'] . 'images/console/background/' .
io_safe_input ($layout["background"]);
$layout["background"];
}
else {
$backgroundImage =
'/include/Image/image_functions.php?getFile=1&thumb=1&thumb_size=' . $mapWidth . 'x' . $mapHeight . '&file=' .
$config['homedir'] . '/images/console/background/' .
io_safe_input ($layout["background"]);
($layout["background"]);
}
}
else {
$mapWidth = $layout["width"];
$mapHeight = $layout["height"];
$backgroundImage = $metaconsole_hack . 'images/console/background/' .
io_safe_input ($layout["background"]);
$layout["background"];
}
if (defined('METACONSOLE')) {

View File

@ -1519,7 +1519,7 @@ function pandoraFlotArea(graph_id, values, labels, labels_long, legend,
// minTickSize
var count_data = datas[0].data.length;
var min_tick_pixels = 80;
var steps = parseInt( count_data / (width/min_tick_pixels));
//~ var steps = parseInt( count_data / (width/min_tick_pixels));
var options = {
series: {
@ -1547,7 +1547,7 @@ function pandoraFlotArea(graph_id, values, labels, labels_long, legend,
axisLabelUseCanvas: false,
axisLabel: xaxisname,
tickFormatter: xFormatter,
minTickSize: steps,
//~ minTickSize: steps,
color: '',
font: font
} ],
@ -1603,25 +1603,26 @@ function pandoraFlotArea(graph_id, values, labels, labels_long, legend,
// Adjust linked graph to the width and position of the main plot
// Miniplot
var overview = $.plot($('#overview_'+graph_id),datas, {
series: {
stack: stacked,
lines: { show: true, lineWidth: 1 },
shadowSize: 0
},
grid: { borderWidth: 1, hoverable: true, autoHighlight: false},
xaxis: { },
xaxes: [ {
tickFormatter: xFormatter,
minTickSize: steps,
color: ''
} ],
yaxis: {ticks: [], autoscaleMargin: 0.1 },
selection: {mode: 'x', color: '#777' },
legend: {show: false},
crosshair: {mode: 'x'}
});
if ( !dashboard ) {
var overview = $.plot($('#overview_'+graph_id),datas, {
series: {
stack: stacked,
lines: { show: true, lineWidth: 1 },
shadowSize: 0
},
grid: { borderWidth: 1, hoverable: true, autoHighlight: false},
xaxis: { },
xaxes: [ {
tickFormatter: xFormatter,
minTickSize: steps,
color: ''
} ],
yaxis: {ticks: [], autoscaleMargin: 0.1 },
selection: {mode: 'x', color: '#777' },
legend: {show: false},
crosshair: {mode: 'x'}
});
}
// Connection between plot and miniplot
$('#' + graph_id).bind('plotselected', function (event, ranges) {
@ -1669,7 +1670,7 @@ function pandoraFlotArea(graph_id, values, labels, labels_long, legend,
plot.setSelection(ranges);
});
var legends = $('#legend_' + graph_id + ' .legendLabel');
//~ var legends = $('#legend_' + graph_id + ' .legendLabel');
var updateLegendTimeout = null;
@ -1768,8 +1769,8 @@ function pandoraFlotArea(graph_id, values, labels, labels_long, legend,
$('#legend_' + graph_id + ' .legendLabel')
.eq(i).css('color','');
//~ $('#legend_' + graph_id + ' .legendLabel')
//~ .eq(i).css('font-family',font+'Font');
$('#legend_' + graph_id + ' .legendLabel')
.eq(i).css('font-family',font+'Font');
i++;
}
@ -1857,7 +1858,7 @@ function pandoraFlotArea(graph_id, values, labels, labels_long, legend,
$('#'+graph_id).bind('mouseout',resetInteractivity);
$('#overview_'+graph_id).bind('mouseout',resetInteractivity);
// Reset interactivity styles
//~ // Reset interactivity styles
function resetInteractivity() {
$('#timestamp_'+graph_id).hide();
dataset = plot.getData();
@ -1891,207 +1892,7 @@ function pandoraFlotArea(graph_id, values, labels, labels_long, legend,
// Prepared to turn series with a checkbox
//return '<div style=color:;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','label'],
//~ 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,dataObject.label]);
//~ });
//~ }
//~ /* [
//~ * {
//~ * '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,
//~ 'label': dataObject.label
//~ });
//~ });
//~ }
//~ if (typeof result === 'undefined')
//~ throw new Error('Empty result');
//~ return result;
//~ }
//~ try {
//~ var elements = [];
//~ var custom_graph = $('input:hidden[name=custom_graph]').value;
//~ if (custom_graph) {
//~ dataObject = retrieveDataOject(dataObjects);
//~ dataObjects.forEach(function (element) {
//~ elements.push(processDataObject(element));
//~ });
//~ graphData = elements;
//~ }
//~ else {
//~ dataObject = retrieveDataOject(dataObjects);
//~ elements.push(processDataObject(dataObject));
//~ graphData = elements;
//~ }
//~ // 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', 0);
//~ $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
//~ id_clicked = this.id.split('_')[3];
//~ // Update the serie clicked
//~ showed[id_clicked] = this.checked;
//~ });
if (menu) {
var parent_height;
$('#menu_overview_' + graph_id).click(function() {
@ -2119,7 +1920,7 @@ function pandoraFlotArea(graph_id, values, labels, labels_long, legend,
//~ event.preventDefault();
//~ plot.exportDataJSON();
//~ });
$('#menu_threshold_' + graph_id).click(function() {
datas = new Array();
@ -2193,12 +1994,12 @@ function pandoraFlotArea(graph_id, values, labels, labels_long, legend,
$('#menu_'+graph_id).parent().css('height').split('px')[0]);
adjust_menu(graph_id, plot, parent_height);
}
if (water_mark) {
set_watermark(graph_id, plot, $('#watermark_image_'+graph_id).attr('src'));
if (!dashboard) {
if (water_mark)
set_watermark(graph_id, plot, $('#watermark_image_'+graph_id).attr('src'));
adjust_menu(graph_id, plot, parent_height, width);
}
adjust_menu(graph_id, plot, parent_height, width);
}
function adjust_menu(graph_id, plot, parent_height, width) {

View File

@ -461,7 +461,7 @@ function flot_area_graph($chart_data, $width, $height, $color, $legend,
// Javascript code
$return .= "<script type='text/javascript'>";
$return .= "//<![CDATA[\n";
$return .= "$(document).ready( function () {";
$return .= "pandoraFlotArea(" .
"'$graph_id', \n" .
"'$values', \n" .
@ -474,7 +474,7 @@ function flot_area_graph($chart_data, $width, $height, $color, $legend,
"$watermark, \n" .
"$width, \n" .
"$max_x, \n" .
"'" . $homeurl . "', \n" .
"'$homeurl', \n" .
"'$unit', \n" .
"$font_size, \n" .
"'$font', \n" .
@ -500,11 +500,8 @@ function flot_area_graph($chart_data, $width, $height, $color, $legend,
"'$xaxisname', \n" .
"'$background_color', \n" .
"'$legend_color'
);";
$return .= "\n//]]>";
$return .= "});";
$return .= "</script>";
// Parent layer