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

(cherry picked from commit 60f0f3378d)
This commit is contained in:
m-lopez-f 2015-11-25 14:25:19 +01:00
parent f705fa2563
commit 2cfbe1014f
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 {
$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;

View File

@ -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 '<img src="' . $no_data_image . '" />';
}
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 '<img src="' . $no_data_image . '" />';
}
if ($flash_chart) {
if ($return) {
return flot_hcolumn_chart(

View File

@ -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+'%)');
}

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,
$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 .= "<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\">
var data = $data;
createGauges(data, '$width', '$height','$font_size');
createGauges(data, '$width', '$height','$font_size','$no_data_image');
</script>";
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));
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();

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,
mininum,maxinum,valor;
for (key in data) {
nombre = data[key].nombre;
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 = 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);
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("<img style='vertical-align:middle;' src='"+ no_data_image +"'/>")
}
}
}