From 2cfbe1014f8005dd26f22a6d47adac9e5b857894 Mon Sep 17 00:00:00 2001 From: m-lopez-f Date: Wed, 25 Nov 2015 14:25:19 +0100 Subject: [PATCH] Fixed many errors in custom graphs and this items in dashboard. Tiquet: #2984,part of #2966 (cherry picked from commit 60f0f3378dda85986a747fbcd5da67a0a18244e0) --- pandora_console/include/functions_graph.php | 5 ++-- pandora_console/include/graphs/fgraph.php | 28 ++++++++++------- .../include/graphs/flot/pandora.flot.js | 5 +++- .../include/graphs/functions_d3.php | 9 ++++-- .../include/graphs/functions_flot.php | 4 ++- pandora_console/include/graphs/pandora.d3.js | 30 ++++++++++++++++--- 6 files changed, 60 insertions(+), 21 deletions(-) diff --git a/pandora_console/include/functions_graph.php b/pandora_console/include/functions_graph.php index 0fbd2c08d3..23c038feaa 100644 --- a/pandora_console/include/functions_graph.php +++ b/pandora_console/include/functions_graph.php @@ -1474,9 +1474,10 @@ function graphic_combined_module ($module_list, $weight_list, $period, else { $value = 0; } - if ($labels[$module] != '') - $temp[$module]['label'] = $labels[$module]; + $temp[$module]['label'] = ($labels[$module] != '') ? $labels[$module] : $temp[$module]['nombre']; + $temp[$module]['value'] = $value; + $temp[$module]['label'] = ui_print_truncate_text($temp[$module]['label'],"module_small",false,true,false,".."); if ($temp[$module]['unit'] == '%'){ $temp[$module]['min'] = 0; diff --git a/pandora_console/include/graphs/fgraph.php b/pandora_console/include/graphs/fgraph.php index 501c3947f2..bc1d5bbdbb 100644 --- a/pandora_console/include/graphs/fgraph.php +++ b/pandora_console/include/graphs/fgraph.php @@ -163,17 +163,20 @@ function slicesbar_graph($chart_data, $period, $width, $height, $colors, } function vbar_graph($flash_chart, $chart_data, $width, $height, - $color = array(), $legend = array(), $xaxisname = "", - $yaxisname = "", $homedir="", $water_mark = '', $font = '', - $font_size = '', $force_steps = true, $ttl = 1, - $reduce_data_columns = false, $adapt_key = '') { + $color, $legend, $long_index, $no_data_image, $xaxisname = "", + $yaxisname = "", $water_mark = "", $font = '', $font_size = '', + $unit = '', $ttl = 1, $homeurl = '', $backgroundColor = 'white') { setup_watermark($water_mark, $water_mark_file, $water_mark_url); + if (empty($chart_data)) { + return ''; + } + if ($flash_chart) { return flot_vcolumn_chart ($chart_data, $width, $height, $color, $legend, $long_index, $homeurl, $unit, $water_mark_url, - $homedir, $reduce_data_columns, $adapt_key); + $homedir); } else { $graph = array(); @@ -451,7 +454,8 @@ function stacked_gauge($flash_chart, $chart_data, $width, $height, $homeurl, $unit, $font, - $font_size + 2 + $font_size + 2, + $no_data_image ); } @@ -540,14 +544,18 @@ function polar_graph($flash_chart, $chart_data, $width, $height, $height, $no_data_image, $ttl, $homedir=""); } + function hbar_graph($flash_chart, $chart_data, $width, $height, - $color = array(), $legend = array(), $xaxisname = "", - $yaxisname = "", $force_height = true, $homedir="", - $water_mark = '', $font = '', $font_size = '', $force_steps = true, - $ttl = 1, $return = false) { + $color, $legend, $long_index, $no_data_image, $xaxisname = "", + $yaxisname = "", $water_mark = "", $font = '', $font_size = '', + $unit = '', $ttl = 1, $homeurl = '', $backgroundColor = 'white') { setup_watermark($water_mark, $water_mark_file, $water_mark_url); + if (empty($chart_data)) { + return ''; + } + if ($flash_chart) { if ($return) { return flot_hcolumn_chart( diff --git a/pandora_console/include/graphs/flot/pandora.flot.js b/pandora_console/include/graphs/flot/pandora.flot.js index 7335d1f07f..737d4bdad6 100644 --- a/pandora_console/include/graphs/flot/pandora.flot.js +++ b/pandora_console/include/graphs/flot/pandora.flot.js @@ -232,7 +232,7 @@ function pandoraFlotPieCustom(graph_id, values, labels, width, return; percent = parseFloat(obj.series.percent).toFixed(2); valor = parseFloat(obj.series.data[0][1]); - console.log(obj); + if (valor > 1000000){ value = Math.round((valor / 1000000)*100)/100; value = value + "M"; @@ -240,7 +240,10 @@ function pandoraFlotPieCustom(graph_id, values, labels, width, value = Math.round((valor / 1000)*100)/100; value = value + "K"; } + else + value = valor; } + alert(''+obj.series.label+': '+ value +' ('+percent+'%)'); } diff --git a/pandora_console/include/graphs/functions_d3.php b/pandora_console/include/graphs/functions_d3.php index 7b64a487d2..10404c7dba 100644 --- a/pandora_console/include/graphs/functions_d3.php +++ b/pandora_console/include/graphs/functions_d3.php @@ -256,7 +256,7 @@ function d3_bullet_chart($chart_data, $width, $height, $color, $legend, } function d3_gauges($chart_data, $width, $height, $color, $legend, - $homeurl, $unit, $font, $font_size) { + $homeurl, $unit, $font, $font_size, $no_data_image) { global $config; if (is_array($chart_data)) @@ -264,12 +264,15 @@ function d3_gauges($chart_data, $width, $height, $color, $legend, $output = include_javascript_d3(true); foreach ($chart_data as $module) { - $output .= ""; + $module['nombre'] = io_safe_output($module['nombre']); + $module['nombre'] = str_replace(array(' ','(',')',"*",' '),'_',$module['nombre']); + $output .= "
"; + } $output .= ""; return $output; diff --git a/pandora_console/include/graphs/functions_flot.php b/pandora_console/include/graphs/functions_flot.php index 39942e926e..adc2f33b78 100644 --- a/pandora_console/include/graphs/functions_flot.php +++ b/pandora_console/include/graphs/functions_flot.php @@ -509,6 +509,8 @@ function flot_custom_pie_chart ($flash_charts, $graph_values, $legendvalue = sprintf("%sM", number_format($value['value'] / 1000000, 2)); else if ($value['value'] > 1000) $legendvalue = sprintf("%sK", number_format($value['value'] / 1000, 2)); + else + $legendvalue = $value['value']; $values[] = $value['value']; $legend[] = $label .": " . $legendvalue . " " .$value['unit']; $labels[] = $label; @@ -639,7 +641,7 @@ function flot_hcolumn_chart ($graph_data, $width, $height, $water_mark) { } // Returns a 3D column chart -function flot_vcolumn_chart ($graph_data, $width, $height, $color, $legend, $long_index, $homeurl, $unit, $water_mark, $homedir, $reduce_data_columns, $adapt_key) { +function flot_vcolumn_chart ($graph_data, $width, $height, $color, $legend, $long_index, $homeurl, $unit, $water_mark, $homedir) { global $config; include_javascript_dependencies_flot_graph(); diff --git a/pandora_console/include/graphs/pandora.d3.js b/pandora_console/include/graphs/pandora.d3.js index 5ccf3271c2..4759c7e67d 100644 --- a/pandora_console/include/graphs/pandora.d3.js +++ b/pandora_console/include/graphs/pandora.d3.js @@ -918,15 +918,31 @@ function createGauge(name, etiqueta, value, min, max, min_warning,max_warning,mi }); } -function createGauges(data, width, height, font_size) +function createGauges(data, width, height, font_size, no_data_image) { var nombre,label,minimun_warning,maximun_warning,minimun_critical,maximun_critical, mininum,maxinum,valor; + for (key in data) { nombre = data[key].nombre; + + nombre = nombre.replace(/ /g,'_'); + nombre = nombre.replace(/(/g,'_'); + nombre = nombre.replace(/)/g,'_'); + nombre = nombre.replace(/\*/g,'_'); + nombre = nombre.replace(/\(/g,'_'); + nombre = nombre.replace(/\)/g,'_'); + label = undefined != data[key].label ? data[key].label : data[key].nombre; + label = label.replace(/ /g,' '); + label = label.replace(/\(/g,'\('); + label = label.replace(/\)/g,'\)'); + + label = label.replace(/(/g,'\('); + label = label.replace(/)/g,'\)'); + minimun_warning = Math.round(parseFloat( data[key].min_warning ),2); maximun_warning = Math.round(parseFloat( data[key].max_warning ),2); minimun_critical = Math.round(parseFloat( data[key].min_critical ),2); @@ -960,9 +976,15 @@ function createGauges(data, width, height, font_size) minimun_warning = mininum; } - createGauge(nombre, label, valor, mininum, maxinum, - minimun_warning, maximun_warning, minimun_critical, - maximun_critical, font_size, height); + if (!isNaN(valor)) { + createGauge(nombre, label, valor, mininum, maxinum, + minimun_warning, maximun_warning, minimun_critical, + maximun_critical, font_size, height); + } + else { + $('#'+nombre).html("") + } + } }