fixed custom graph

This commit is contained in:
daniel 2018-04-27 13:51:13 +02:00
parent 30dc841bae
commit b11e256c8b
4 changed files with 48 additions and 369 deletions

View File

@ -965,7 +965,7 @@ return $return;
$config['homedir'] . "/images/logo_vertical_water.png",
'url' => ui_get_full_url("images/logo_vertical_water.png", false, false, false));
}
if ($type_graph === 'area') {
if ($compare === 'separated') {
return
@ -1008,29 +1008,7 @@ return $return;
}
}
elseif ($type_graph === 'line') {
if ($compare === 'separated') {
return
line_graph($flash_chart, $chart, $width, $height/2, $color,
$legend, $long_index,
ui_get_full_url("images/image_problem_area_small.png", false, false, false),
$title, $unit, $water_mark, $config['fontpath'],
$config['font_size'], $unit, $ttl, $homeurl, $backgroundColor).
'<br>'.
line_graph($flash_chart, $chart_prev, $width, $height/2, $color,
$legend, $long_index,
ui_get_full_url("images/image_problem_area_small.png", false, false, false),
$title, $unit, $water_mark, $config['fontpath'],
$config['font_size'], $unit, $ttl, $homeurl, $backgroundColor);
}
else {
// Color commented not to restrict serie colors
return
line_graph($flash_chart, $chart, $width, $height, $color,
$legend, $long_index,
ui_get_full_url("images/image_problem_area_small.png", false, false, false),
$title, $unit, $water_mark, $config['fontpath'],
$config['font_size'], $unit, $ttl, $homeurl, $backgroundColor);
}
}
}
@ -1098,7 +1076,6 @@ function graphic_combined_module ( $module_list, $weight_list, $period, $width,
//XXX colocar
/*
$stacked
$prediction_period
$name_list
$unit_list
@ -1112,7 +1089,6 @@ function graphic_combined_module ( $module_list, $weight_list, $period, $width,
$modules_series
*/
html_debug_print($stacked);
html_debug_print($name_list);
html_debug_print($unit_list);
html_debug_print($from_interface);
@ -1134,9 +1110,7 @@ html_debug_print($from_interface);
$show_elements_graph['show_unknown'] = false; // dont use
$show_elements_graph['avg_only'] = false; // dont use
$show_elements_graph['fullscale'] = $fullscale;
//XXXX
$show_elements_graph['show_title'] = $show_title; // dont use
$show_elements_graph['show_title'] = ''; // dont use
$show_elements_graph['menu'] = $menu; // dont use
$show_elements_graph['adapt_key'] = ''; // dont use
$show_elements_graph['percentil'] = $percentil;
@ -1150,6 +1124,7 @@ html_debug_print($from_interface);
$show_elements_graph['return_data'] = true; //dont use
$show_elements_graph['id_widget'] = $id_widget_dashboard;
$show_elements_graph['labels'] = $labels;
$show_elements_graph['stacked'] = $stacked;
$format_graph = array();
$format_graph['width'] = $width;
@ -1159,7 +1134,6 @@ html_debug_print($from_interface);
$format_graph['unit_name'] = $unit_name;
$format_graph['unit'] = ''; //dont use
$format_graph['title'] = $title;
$format_graph['homeurl'] = $homeurl;
$format_graph['ttl'] = $ttl;
@ -1167,7 +1141,7 @@ html_debug_print($from_interface);
$format_graph['font'] = $config['fontpath'];
$format_graph['font-size'] = $config['font_size'];
/*
//for flash_charts
$user = users_get_user_by_id($config['id_user']);
$user_flash_charts = $user['flash_chart'];
@ -1181,12 +1155,10 @@ html_debug_print($from_interface);
if ($only_image) {
$flash_charts = false;
}
*/
$i=0;
$array_data = array();
foreach ($module_list as $key => $agent_module_id) {
$module_data = db_get_row_sql (
'SELECT * FROM tagente_modulo
WHERE id_agente_modulo = ' .
@ -1882,37 +1854,17 @@ html_debug_print($from_interface);
}
switch ($stacked) {
default:
case CUSTOM_GRAPH_STACKED_LINE:
case CUSTOM_GRAPH_STACKED_AREA:
case CUSTOM_GRAPH_AREA:
case CUSTOM_GRAPH_LINE:
return area_graph($agent_module_id, $array_data, $color,
$legend, $series_type, $date_array,
$data_module_graph, $show_elements_graph,
$format_graph, $water_mark, $series_suffix_str,
$array_events_alerts);
break;
default:
case CUSTOM_GRAPH_STACKED_AREA:
html_debug_print('entra por akiiii');
return stacked_area_graph($flash_charts, $array_data,
$width, $height, $color, $module_name_list, $long_index,
ui_get_full_url("images/image_problem_area_small.png", false, false, false),
$title, "", $water_mark, $config['fontpath'], $fixed_font_size,
"", $ttl, $homeurl, $background_color,$dashboard, $vconsole);
break;
case CUSTOM_GRAPH_LINE:
return line_graph($flash_charts, $graph_values, $width,
$height, $color, $module_name_list, $long_index,
ui_get_full_url("images/image_problem_area_small.png", false, false, false),
$title, "", $water_mark, $config['fontpath'], $fixed_font_size,
$unit, $ttl, $homeurl, $background_color, $dashboard,
$vconsole, $series_type, $percentil_result, $yellow_threshold, $red_threshold, $threshold_data);
break;
case CUSTOM_GRAPH_STACKED_LINE:
return stacked_line_graph($flash_charts, $graph_values,
$width, $height, $color, $module_name_list, $long_index,
ui_get_full_url("images/image_problem_area_small.png", false, false, false),
"", "", $water_mark, $config['fontpath'], $fixed_font_size,
"", $ttl, $homeurl, $background_color, $dashboard, $vconsole);
break;
case CUSTOM_GRAPH_BULLET_CHART_THRESHOLD:
case CUSTOM_GRAPH_BULLET_CHART:
return stacked_bullet_chart($flash_charts, $graph_values,

View File

@ -250,6 +250,8 @@ function area_graph(
else {
//XXXXX
//Corregir este problema
//tener en cuenta stacked, area, line
$graph = array();
$graph['data'] = $chart_data;
$graph['width'] = $width;
@ -278,132 +280,6 @@ function area_graph(
}
}
function stacked_area_graph($flash_chart, $chart_data, $width, $height,
$color, $legend, $long_index, $no_data_image, $xaxisname = "",
$yaxisname = "", $water_mark = "", $font = '', $font_size = '',
$unit = '', $ttl = 1, $homeurl = '', $backgroundColor = 'white',
$dashboard = false, $vconsole = false, $agent_module_id) {
setup_watermark($water_mark, $water_mark_file, $water_mark_url);
if (empty($chart_data)) {
return '<img src="' . $no_data_image . '" />';
}
$menu = (!$dashboard && !$vconsole);
if ($flash_chart) {
return flot_area_stacked_graph(
$chart_data,
$width,
$height,
$color,
$legend,
$long_index,
$homeurl,
$font,
$font_size,
$unit,
$water_mark_url,
array(),
array(),
0,
0,
'',
false,
'',
$menu,
$backgroundColor,
$dashboard,
$vconsole,
$agent_module_id);
}
else {
//Stack the data
stack_data($chart_data, $legend, $color);
$graph = array();
$graph['data'] = $chart_data;
$graph['width'] = $width;
$graph['height'] = $height;
$graph['color'] = $color;
$graph['legend'] = $legend;
$graph['xaxisname'] = $xaxisname;
$graph['yaxisname'] = $yaxisname;
$graph['water_mark'] = $water_mark_file;
$graph['font'] = $font;
$graph['font_size'] = $font_size;
$graph['backgroundColor'] = $backgroundColor;
$id_graph = serialize_in_temp($graph, null, $ttl);
return "<img src='" . ui_get_full_url (false, false, false, false) .
"include/graphs/functions_pchart.php?static_graph=1&graph_type=stacked_area&ttl=".$ttl."&id_graph=" . $id_graph . "' />";
}
}
function stacked_line_graph($flash_chart, $chart_data, $width, $height,
$color, $legend, $long_index, $no_data_image, $xaxisname = "",
$yaxisname = "", $water_mark = "", $font = '', $font_size = '',
$unit = '', $ttl = 1, $homeurl = '', $backgroundColor = 'white',
$dashboard = false, $vconsole = false) {
setup_watermark($water_mark, $water_mark_file, $water_mark_url);
if (empty($chart_data)) {
return '<img src="' . $no_data_image . '" />';
}
$menu = (!$dashboard && !$vconsole);
if ($flash_chart) {
return flot_line_stacked_graph(
$chart_data,
$width,
$height,
$color,
$legend,
$long_index,
$homeurl,
$font,
$font_size,
$unit,
$water_mark_url,
array(),
array(),
0,
0,
'',
false,
'',
$menu,
$backgroundColor,
$dashboard,
$vconsole);
}
else {
//Stack the data
stack_data($chart_data, $legend, $color);
$graph = array();
$graph['data'] = $chart_data;
$graph['width'] = $width;
$graph['height'] = $height;
$graph['color'] = $color;
$graph['legend'] = $legend;
$graph['xaxisname'] = $xaxisname;
$graph['yaxisname'] = $yaxisname;
$graph['water_mark'] = $water_mark_file;
$graph['font'] = $font;
$graph['font_size'] = $font_size;
$graph['backgroundColor'] = $backgroundColor;
$id_graph = serialize_in_temp($graph, null, $ttl);
return "<img src='" . $homeurl . "include/graphs/functions_pchart.php?static_graph=1&graph_type=line&ttl=".$ttl."&id_graph=" . $id_graph . "' />";
}
}
function stacked_bullet_chart($flash_chart, $chart_data, $width, $height,
$color, $legend, $long_index, $no_data_image, $xaxisname = "",
$yaxisname = "", $water_mark = "", $font = '', $font_size = '',
@ -487,77 +363,6 @@ function stacked_gauge($flash_chart, $chart_data, $width, $height,
);
}
function line_graph($flash_chart, $chart_data, $width, $height, $color,
$legend, $long_index, $no_data_image, $xaxisname = "",
$yaxisname = "", $water_mark = "", $font = '', $font_size = '',
$unit = '', $ttl = 1, $homeurl = '', $backgroundColor = 'white',
$dashboard = false, $vconsole = false, $series_type = array(),
$percentil_values = array(), $yellow_threshold = 0, $red_threshold = 0,
$threshold_data = array()) {
include_once("functions_flot.php");
setup_watermark($water_mark, $water_mark_file, $water_mark_url);
if (empty($chart_data)) {
return '<img src="' . $no_data_image . '" />';
}
$menu = (!$dashboard && !$vconsole);
if ($flash_chart) {
return flot_line_simple_graph(
$chart_data,
$width,
$height,
$color,
$legend,
$long_index,
$homeurl,
$font,
$font_size,
$unit,
$water_mark_url,
$series_type,
array(),
$yellow_threshold,
$red_threshold,
'',
false,
'',
$menu,
$backgroundColor,
$dashboard,
$vconsole,
false,
$percentil_values,
$threshold_data,
$xaxisname);
}
else {
$graph = array();
$graph['data'] = $chart_data;
$graph['width'] = $width;
$graph['height'] = $height;
$graph['color'] = $color;
$graph['legend'] = $legend;
$graph['xaxisname'] = $xaxisname;
$graph['yaxisname'] = $yaxisname;
$graph['water_mark'] = $water_mark_file;
$graph['font'] = $font;
$graph['font_size'] = $font_size;
$graph['backgroundColor'] = $backgroundColor;
$graph['percentil'] = $percentil_values;
$id_graph = serialize_in_temp($graph, null, $ttl);
if(empty($homeurl)){
return "<img src='" . ui_get_full_url (false, false, false, false) . "include/graphs/functions_pchart.php?static_graph=1&graph_type=line&ttl=".$ttl."&id_graph=" . $id_graph . "' />";
}else{
return "<img src='" . $homeurl . "include/graphs/functions_pchart.php?static_graph=1&graph_type=line&ttl=".$ttl."&id_graph=" . $id_graph . "' />";
}
}
}
function kiviat_graph($graph_type, $flash_chart, $chart_data, $width,
$height, $no_data_image, $ttl = 1, $homedir="") {

View File

@ -1143,6 +1143,7 @@ function pandoraFlotArea(
var dashboard = show_elements_graph.dashboard;
var menu = show_elements_graph.menu;
var max_x = date_array['final_date'] *1000;
var type = show_elements_graph.stacked;
//for threshold
var threshold = true;
@ -1155,30 +1156,29 @@ function pandoraFlotArea(
var red_inverse = parseInt (data_module_graph.c_inv);
//XXXX ver que hay que hacer
var type = 'area_simple';
var labels_long = '';
var min_check = 0;
var water_mark = '';
var legend_events = null;
var legend_alerts = null;
switch (type) {
case 'line_simple':
stacked = null;
filled = false;
case 2:
stacked = null;
filled_s = false;
break;
case 'line_stacked':
stacked = 'stack';
filled = false;
case 3:
stacked = 'stack';
filled_s = false;
break;
case 'area_simple':
stacked = null;
filled = true;
default:
case 0:
stacked = null;
filled_s = 0.2;
break;
case 'area_stacked':
stacked = 'stack';
filled = true;
case 1:
stacked = 'stack';
filled_s = 0.2;
break;
}
@ -1203,7 +1203,7 @@ function pandoraFlotArea(
case 'area':
line_show = true;
points_show = false; // XXX - false
filled = 0.2;
filled = filled_s;
steps_chart = false;
radius = false;
fill_points = fill_color;
@ -1230,7 +1230,7 @@ function pandoraFlotArea(
case 'boolean':
line_show = true;
points_show = false;
filled = true;
filled = false;
steps_chart = true;
radius = false;
fill_points = fill_color;
@ -2448,7 +2448,7 @@ function set_watermark(graph_id, plot, watermark_src) {
if ($('#'+graph_id+' .yAxis .tickLabel').eq(0).css('height') != undefined) {
down_ticks_height = $('#'+graph_id+' .yAxis .tickLabel').eq(0).css('height').split('px')[0];
}
var left_pos = parseInt(context.canvas.width - 3) - $('#watermark_image_'+graph_id)[0].width;
var top_pos = 6;
//var top_pos = parseInt(context.canvas.height - down_ticks_height - 10) - $('#watermark_image_'+graph_id)[0].height;
@ -2561,12 +2561,11 @@ function pad(input, length, padding) {
}
// Recalculate the threshold data depends on warning and critical
function axis_thresholded (threshold_data, y_min, y_max, red_threshold, extremes, red_up) {
var y = {
min: 0,
max: 0
};
// Default values
var yaxis_resize = {
up: null,
@ -2597,10 +2596,10 @@ function axis_thresholded (threshold_data, y_min, y_max, red_threshold, extremes
if (yaxis_resize['normal_down'] > this.data[0][1]) yaxis_resize['normal_down'] = this.data[0][1];
}
});
// If you need to display a up or a down bar, display 10% of data height
var margin_up_or_down = (y_max - y_min)*0.10;
// Calculate the new axis
y['max'] = yaxis_resize['normal_up'] > y_max ? yaxis_resize['normal_up'] : y_max;
y['min'] = yaxis_resize['normal_down'] > y_min ? yaxis_resize['normal_down'] : y_min;
@ -2614,14 +2613,15 @@ function axis_thresholded (threshold_data, y_min, y_max, red_threshold, extremes
? yaxis_resize['up'] + margin_up_or_down
: y_min;
}
return y;
}
function add_threshold (data_base, threshold_data, y_min, y_max,
red_threshold, extremes, red_up) {
var datas = new Array ();
$.each(data_base, function() {
// Prepared to turning series
//if(showed[this.id.split('_')[1]]) {
@ -2637,7 +2637,7 @@ function add_threshold (data_base, threshold_data, y_min, y_max,
if (/_down/.test(this.id)){
var end;
if (/critical/.test(this.id)) {
end = red_threshold;
end = red_threshold;
} else {
end = extremes[this.id];
}
@ -2659,10 +2659,10 @@ function add_threshold (data_base, threshold_data, y_min, y_max,
if (end > y_max) {
this.bars.barWidth = y_max - this.data[0][1];
}
}
}
datas.push(this);
});
return datas;
}

View File

@ -20,17 +20,17 @@ global $config;
function include_javascript_dependencies_flot_graph($return = false) {
global $config;
static $is_include_javascript = false;
if (!$is_include_javascript) {
$is_include_javascript = true;
$metaconsole_hack = '';
if (defined('METACONSOLE')) {
$metaconsole_hack = '../../';
}
// NOTE: jquery.flot.threshold is not te original file. Is patched to allow multiple thresholds and filled area
$output = '
<!--[if lte IE 8]><script language="javascript" type="text/javascript" src="' . ui_get_full_url($metaconsole_hack . '/include/graphs/flot/excanvas.js') . '"></script><![endif]-->
@ -58,12 +58,12 @@ function include_javascript_dependencies_flot_graph($return = false) {
ui_get_full_url($metaconsole_hack . '/include/graphs/flot/jquery.flot.exportdata.pandora.js') .'"></script>
<script language="javascript" type="text/javascript" src="'.
ui_get_full_url($metaconsole_hack . '/include/graphs/flot/jquery.flot.axislabels.js') .'"></script>
<script language="javascript" type="text/javascript" src="'.
<script language="javascript" type="text/javascript" src="'.
ui_get_full_url($metaconsole_hack . '/include/graphs/flot/pandora.flot.js') .'"></script>';
$output .= "
<script type='text/javascript'>
var precision_graph = " . $config['graph_precision'] . ";
function pieHover(event, pos, obj)
function pieHover(event, pos, obj)
{
if (!obj)
return;
@ -78,8 +78,8 @@ function include_javascript_dependencies_flot_graph($return = false) {
}
});
}
function pieClick(event, pos, obj)
function pieClick(event, pos, obj)
{
if (!obj)
return;
@ -87,10 +87,10 @@ function include_javascript_dependencies_flot_graph($return = false) {
alert(''+obj.series.label+': '+obj.series.data[0][1]+' ('+percent+'%)');
}
</script>";
if (!$return)
echo $output;
return $output;
}
}
@ -98,84 +98,6 @@ function include_javascript_dependencies_flot_graph($return = false) {
///////////////////////////////
////////// AREA GRAPHS ////////
///////////////////////////////
function flot_area_stacked_graph($chart_data, $width, $height, $color,
$legend, $long_index, $homeurl = '', $font = '', $font_size = 7,
$unit = '', $water_mark = '', $serie_types = array(),
$chart_extra_data = array(), $yellow_threshold = 0,
$red_threshold = 0, $adapt_key= '', $force_integer = false,
$series_suffix_str = '', $menu = true, $background_color = 'white',
$dashboard = false, $vconsole = false, $agent_module_id = 0) {
global $config;
return flot_area_graph($chart_data, $width, $height, $color,
$legend, $long_index, $homeurl, $unit, 'area_stacked',
$water_mark, $serie_types, $chart_extra_data, $yellow_threshold,
$red_threshold, $adapt_key, $force_integer, $series_suffix_str,
$menu, $background_color, $dashboard, $vconsole,
$agent_module_id, $font, $font_size);
}
function flot_area_simple_graph($chart_data, $width, $height, $color,
$legend, $long_index, $homeurl = '', $unit = '', $water_mark = '',
$serie_types = array(), $chart_extra_data = array(),
$yellow_threshold = 0, $red_threshold = 0, $adapt_key= '',
$force_integer = false, $series_suffix_str = '', $menu = true,
$background_color = 'white', $dashboard = false, $vconsole = false,
$agent_module_id = 0, $font = '', $font_size = 7, $xaxisname = '',
$percentil_values = array(), $threshold_data = array()) {
global $config;
return flot_area_graph($chart_data, $width, $height, $color,
$legend, $long_index, $homeurl, $unit, 'area_simple',
$water_mark, $serie_types, $chart_extra_data, $yellow_threshold,
$red_threshold, $adapt_key, $force_integer, $series_suffix_str,
$menu, $background_color, $dashboard, $vconsole,
$agent_module_id, $font, $font_size, $xaxisname, $percentil_values,
$threshold_data);
}
function flot_line_stacked_graph($chart_data, $width, $height, $color,
$legend, $long_index, $homeurl = '', $font = '', $font_size = 7,
$unit = '', $water_mark = '', $serie_types = array(),
$chart_extra_data = array(), $yellow_threshold = 0,
$red_threshold = 0, $adapt_key= '', $force_integer = false,
$series_suffix_str = '', $menu = true, $background_color = 'white',
$dashboard = false, $vconsole = false, $agent_module_id = 0,
$xaxisname = "") {
global $config;
return flot_area_graph($chart_data, $width, $height, $color,
$legend, $long_index, $homeurl, $unit, 'line_stacked',
$water_mark, $serie_types, $chart_extra_data, $yellow_threshold,
$red_threshold, $adapt_key, $force_integer, $series_suffix_str,
$menu, $background_color, $dashboard, $vconsole,
$agent_module_id, $font, $font_size, $xaxisname);
}
function flot_line_simple_graph($chart_data, $width, $height, $color,
$legend, $long_index, $homeurl = '', $font = '', $font_size = 7,
$unit = '', $water_mark = '', $serie_types = array(),
$chart_extra_data = array(), $yellow_threshold = 0,
$red_threshold = 0, $adapt_key= '', $force_integer = false,
$series_suffix_str = '', $menu = true, $background_color = 'white',
$dashboard = false, $vconsole = false, $agent_module_id = 0,
$percentil_values = array(), $threshold_data = array(),
$xaxisname = '') {
global $config;
return flot_area_graph($chart_data, $width, $height, $color,
$legend, $long_index, $homeurl, $unit, 'line_simple',
$water_mark, $serie_types, $chart_extra_data, $yellow_threshold,
$red_threshold, $adapt_key, $force_integer, $series_suffix_str,
$menu, $background_color, $dashboard, $vconsole,
$agent_module_id, $font, $font_size, $xaxisname, $percentil_values,
$threshold_data);
}
function flot_area_graph (
$agent_module_id, $array_data, $color,
$legend, $series_type, $date_array,