Fixed many errors in custom graphs and this items in dashboard. Tiquet: #2984,part of #2966

This commit is contained in:
m-lopez-f 2015-11-25 14:25:19 +01:00
parent 1ff0ba2096
commit 60f0f3378d
6 changed files with 60 additions and 21 deletions

View File

@ -1474,9 +1474,10 @@ function graphic_combined_module ($module_list, $weight_list, $period,
else { else {
$value = 0; $value = 0;
} }
if ($labels[$module] != '') $temp[$module]['label'] = ($labels[$module] != '') ? $labels[$module] : $temp[$module]['nombre'];
$temp[$module]['label'] = $labels[$module];
$temp[$module]['value'] = $value; $temp[$module]['value'] = $value;
$temp[$module]['label'] = ui_print_truncate_text($temp[$module]['label'],"module_small",false,true,false,"..");
if ($temp[$module]['unit'] == '%'){ if ($temp[$module]['unit'] == '%'){
$temp[$module]['min'] = 0; $temp[$module]['min'] = 0;

View File

@ -163,17 +163,20 @@ function slicesbar_graph($chart_data, $period, $width, $height, $colors,
} }
function vbar_graph($flash_chart, $chart_data, $width, $height, function vbar_graph($flash_chart, $chart_data, $width, $height,
$color = array(), $legend = array(), $xaxisname = "", $color, $legend, $long_index, $no_data_image, $xaxisname = "",
$yaxisname = "", $homedir="", $water_mark = '', $font = '', $yaxisname = "", $water_mark = "", $font = '', $font_size = '',
$font_size = '', $force_steps = true, $ttl = 1, $unit = '', $ttl = 1, $homeurl = '', $backgroundColor = 'white') {
$reduce_data_columns = false, $adapt_key = '') {
setup_watermark($water_mark, $water_mark_file, $water_mark_url); setup_watermark($water_mark, $water_mark_file, $water_mark_url);
if (empty($chart_data)) {
return '<img src="' . $no_data_image . '" />';
}
if ($flash_chart) { if ($flash_chart) {
return flot_vcolumn_chart ($chart_data, $width, $height, $color, return flot_vcolumn_chart ($chart_data, $width, $height, $color,
$legend, $long_index, $homeurl, $unit, $water_mark_url, $legend, $long_index, $homeurl, $unit, $water_mark_url,
$homedir, $reduce_data_columns, $adapt_key); $homedir);
} }
else { else {
$graph = array(); $graph = array();
@ -451,7 +454,8 @@ function stacked_gauge($flash_chart, $chart_data, $width, $height,
$homeurl, $homeurl,
$unit, $unit,
$font, $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=""); $height, $no_data_image, $ttl, $homedir="");
} }
function hbar_graph($flash_chart, $chart_data, $width, $height, function hbar_graph($flash_chart, $chart_data, $width, $height,
$color = array(), $legend = array(), $xaxisname = "", $color, $legend, $long_index, $no_data_image, $xaxisname = "",
$yaxisname = "", $force_height = true, $homedir="", $yaxisname = "", $water_mark = "", $font = '', $font_size = '',
$water_mark = '', $font = '', $font_size = '', $force_steps = true, $unit = '', $ttl = 1, $homeurl = '', $backgroundColor = 'white') {
$ttl = 1, $return = false) {
setup_watermark($water_mark, $water_mark_file, $water_mark_url); setup_watermark($water_mark, $water_mark_file, $water_mark_url);
if (empty($chart_data)) {
return '<img src="' . $no_data_image . '" />';
}
if ($flash_chart) { if ($flash_chart) {
if ($return) { if ($return) {
return flot_hcolumn_chart( return flot_hcolumn_chart(

View File

@ -232,7 +232,7 @@ function pandoraFlotPieCustom(graph_id, values, labels, width,
return; return;
percent = parseFloat(obj.series.percent).toFixed(2); percent = parseFloat(obj.series.percent).toFixed(2);
valor = parseFloat(obj.series.data[0][1]); valor = parseFloat(obj.series.data[0][1]);
console.log(obj);
if (valor > 1000000){ if (valor > 1000000){
value = Math.round((valor / 1000000)*100)/100; value = Math.round((valor / 1000000)*100)/100;
value = value + "M"; value = value + "M";
@ -240,7 +240,10 @@ function pandoraFlotPieCustom(graph_id, values, labels, width,
value = Math.round((valor / 1000)*100)/100; value = Math.round((valor / 1000)*100)/100;
value = value + "K"; value = value + "K";
} }
else
value = valor;
} }
alert(''+obj.series.label+': '+ value +' ('+percent+'%)'); alert(''+obj.series.label+': '+ value +' ('+percent+'%)');
} }

View File

@ -256,7 +256,7 @@ function d3_bullet_chart($chart_data, $width, $height, $color, $legend,
} }
function d3_gauges($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; global $config;
if (is_array($chart_data)) if (is_array($chart_data))
@ -264,12 +264,15 @@ function d3_gauges($chart_data, $width, $height, $color, $legend,
$output = include_javascript_d3(true); $output = include_javascript_d3(true);
foreach ($chart_data as $module) { foreach ($chart_data as $module) {
$output .= "<span id='".str_replace('&#x20;','_',$module['nombre'])."' style='overflow: hidden; margin-left: 10px;'></span>"; $module['nombre'] = io_safe_output($module['nombre']);
$module['nombre'] = str_replace(array('&#x20;','(',')',"*",' '),'_',$module['nombre']);
$output .= "<div id='".$module['nombre']."' style='float:left; overflow: hidden; margin-left: 10px;'></div>";
} }
$output .= "<script language=\"javascript\" type=\"text/javascript\"> $output .= "<script language=\"javascript\" type=\"text/javascript\">
var data = $data; var data = $data;
createGauges(data, '$width', '$height','$font_size'); createGauges(data, '$width', '$height','$font_size','$no_data_image');
</script>"; </script>";
return $output; return $output;

View File

@ -509,6 +509,8 @@ function flot_custom_pie_chart ($flash_charts, $graph_values,
$legendvalue = sprintf("%sM", number_format($value['value'] / 1000000, 2)); $legendvalue = sprintf("%sM", number_format($value['value'] / 1000000, 2));
else if ($value['value'] > 1000) else if ($value['value'] > 1000)
$legendvalue = sprintf("%sK", number_format($value['value'] / 1000, 2)); $legendvalue = sprintf("%sK", number_format($value['value'] / 1000, 2));
else
$legendvalue = $value['value'];
$values[] = $value['value']; $values[] = $value['value'];
$legend[] = $label .": " . $legendvalue . " " .$value['unit']; $legend[] = $label .": " . $legendvalue . " " .$value['unit'];
$labels[] = $label; $labels[] = $label;
@ -639,7 +641,7 @@ function flot_hcolumn_chart ($graph_data, $width, $height, $water_mark) {
} }
// Returns a 3D column chart // 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; global $config;
include_javascript_dependencies_flot_graph(); include_javascript_dependencies_flot_graph();

View File

@ -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, var nombre,label,minimun_warning,maximun_warning,minimun_critical,maximun_critical,
mininum,maxinum,valor; mininum,maxinum,valor;
for (key in data) { for (key in data) {
nombre = data[key].nombre; nombre = data[key].nombre;
nombre = nombre.replace(/&#x20;/g,'_'); nombre = nombre.replace(/&#x20;/g,'_');
nombre = nombre.replace(/&#40;/g,'_');
nombre = nombre.replace(/&#41;/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 = undefined != data[key].label ? data[key].label : data[key].nombre;
label = label.replace(/&#x20;/g,' '); label = label.replace(/&#x20;/g,' ');
label = label.replace(/\(/g,'\(');
label = label.replace(/\)/g,'\)');
label = label.replace(/&#40;/g,'\(');
label = label.replace(/&#41;/g,'\)');
minimun_warning = Math.round(parseFloat( data[key].min_warning ),2); minimun_warning = Math.round(parseFloat( data[key].min_warning ),2);
maximun_warning = Math.round(parseFloat( data[key].max_warning ),2); maximun_warning = Math.round(parseFloat( data[key].max_warning ),2);
minimun_critical = Math.round(parseFloat( data[key].min_critical ),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; minimun_warning = mininum;
} }
createGauge(nombre, label, valor, mininum, maxinum, if (!isNaN(valor)) {
minimun_warning, maximun_warning, minimun_critical, createGauge(nombre, label, valor, mininum, maxinum,
maximun_critical, font_size, height); minimun_warning, maximun_warning, minimun_critical,
maximun_critical, font_size, height);
}
else {
$('#'+nombre).html("<img style='vertical-align:middle;' src='"+ no_data_image +"'/>")
}
} }
} }