2014-06-13 Sergio Martin <sergio.martin@artica.es>

* godmode/reporting/visual_console_builder.editor.js
	include/graphs/fgraph.php
	include/graphs/functions_pchart.php
	include/graphs/pChart/pImage.class.php
	include/functions_visual_map.php
	include/ajax/visual_console_builder.ajax.php
	include/functions_visual_map_editor.php
	include/functions_custom_graphs.php
	include/functions_graph.php: Added option to cusomize the
	background of the graphs in visual consoles for ticket: #886



git-svn-id: https://svn.code.sf.net/p/pandora/code/trunk@10181 c3f86ba8-e40f-0410-aaad-9ba5e7f4b01f
This commit is contained in:
zarzuelo 2014-06-13 07:53:50 +00:00
parent b10e018c2a
commit e2a8e90b2a
10 changed files with 138 additions and 37 deletions

View File

@ -1,3 +1,16 @@
2014-06-13 Sergio Martin <sergio.martin@artica.es>
* godmode/reporting/visual_console_builder.editor.js
include/graphs/fgraph.php
include/graphs/functions_pchart.php
include/graphs/pChart/pImage.class.php
include/functions_visual_map.php
include/ajax/visual_console_builder.ajax.php
include/functions_visual_map_editor.php
include/functions_custom_graphs.php
include/functions_graph.php: Added option to cusomize the
background of the graphs in visual consoles for ticket: #886
2014-06-13 Vanessa Gil <vanessa.gil@artica.es>
* include/languages/ca.mo

View File

@ -221,6 +221,7 @@ function readFields() {
values['label'] = text;
values['image'] = $("select[name=image]").val();
values['background_color'] = $("select[name=background_color]").val();
values['left'] = $("input[name=left]").val();
values['top'] = $("input[name=top]").val();
values['agent'] = $("input[name=agent]").val();
@ -472,7 +473,7 @@ function loadFieldsFromDB(item) {
var moduleId = 0;
fill_parent_select(idItem);
console.log(data);
jQuery.each(data, function(key, val) {
if (key == 'background')
$("#background_image").val(val);
@ -503,8 +504,10 @@ function loadFieldsFromDB(item) {
if (key == 'image') {
//Load image preview
$("select[name=image]").val(val);
$("select[name=background_color]").val(val);
showPreview(val);
}
if (key == 'pos_x') $("input[name=left]").val(val);
if (key == 'pos_y') $("input[name=top]").val(val);
if (key == 'agent_name') {
@ -740,6 +743,9 @@ function hiddenFields(item) {
$("#module_graph_size_row").css('display', 'none');
$("#module_graph_size_row." + item).css('display', '');
$("#background_color").css('display', 'none');
$("#background_color." + item).css('display', '');
$("#radio_choice_graph").css('display', 'none');
$("#radio_choice_graph." + item).css('display', '');
@ -827,6 +833,8 @@ function getModuleGraph(id_data) {
height = data['height'];
width = data['width'];
period = data['period'];
background_color = data['image'];
if (metaconsole != 0) {
id_metaconsole = data['id_metaconsole'];
}
@ -847,6 +855,7 @@ function getModuleGraph(id_data) {
parameter.push ({name: "height", value: height});
parameter.push ({name: "width", value: width});
parameter.push ({name: "period", value: period});
parameter.push ({name: "background_color", value: background_color});
jQuery.ajax({
async: false,
url: url_ajax,

View File

@ -45,6 +45,7 @@ $id_element = get_parameter('id_element', null);
$image = get_parameter('image', null);
$background = get_parameter('background', null);
$background_color = get_parameter('background_color', null);
$label = get_parameter('label', '');
$left = get_parameter('left', null);
$top = get_parameter('top', null);
@ -100,12 +101,13 @@ switch ($action) {
if ($id_custom_graph != 0) {
$img = custom_graphs_print(
$id_custom_graph, $height, $width, $period,
true, true, 0, true);
true, true, 0, true, $background_color);
}
else {
$img = grafico_modulo_sparse($id_agent_module,
$period, false, $width, $height, '', null, false, 1,
false, 0, '', 0, 0, true, true);
false, 0, '', 0, 0, true, true, '', 1, false, '',
false, false, true, $background_color);
}
//Restore db connection
@ -124,7 +126,7 @@ switch ($action) {
case 'get_layout_data':
$layoutData = db_get_row_filter('tlayout_data',
array('id' => $id_element));
echo json_encode($layoutData);
break;
@ -304,6 +306,12 @@ switch ($action) {
case 'update':
case 'move':
$values = array();
// In Graphs, background color is stored in column image (sorry)
if ($type == 'module_graph') {
$values['image'] = $background_color;
}
switch ($type) {
case 'background':
if ($background !== null)
@ -438,8 +446,12 @@ switch ($action) {
}
if ($action == 'move') {
//Don't change the label because only change the positions
// Don't change the label because only change the positions
unset($values['label']);
// Don't change background color in graphs when move
if ($type == 'module_graph') {
unset($values['image']);
}
}
$result = db_process_sql_update('tlayout_data', $values, array('id' => $id_element));

View File

@ -93,7 +93,8 @@ function custom_graphs_get_user ($id_user = 0, $only_names = false, $returnAllGr
*/
function custom_graphs_print($id_graph, $height, $width, $period,
$stacked = null, $return = false, $date = 0, $only_image = false) {
$stacked = null, $return = false, $date = 0, $only_image = false,
$background_color = 'white') {
global $config;
$graph_conf = db_get_row('tgraph', 'id_graph', $id_graph);
@ -118,7 +119,8 @@ function custom_graphs_print($id_graph, $height, $width, $period,
}
$output = graphic_combined_module($modules, $weights, $period,
$width, $height, '', '', 0, 0, 0, $stacked, $date, $only_image);
$width, $height, '', '', 0, 0, 0, $stacked, $date, $only_image,
'', 1, false, false, $background_color);
if ($return)
return $output;

View File

@ -710,7 +710,7 @@ function grafico_modulo_sparse ($agent_module_id, $period, $show_events,
$date = 0, $unit = '', $baseline = 0, $return_data = 0,
$show_title = true, $only_image = false, $homeurl = '', $ttl = 1,
$projection = false, $adapt_key = '', $compare = false, $show_unknown = false,
$menu = true) {
$menu = true, $backgroundColor = 'white') {
global $config;
global $graphic_type;
@ -801,19 +801,22 @@ function grafico_modulo_sparse ($agent_module_id, $period, $show_events,
return area_graph($flash_chart, $chart, $width, $height/2, $color, $legend,
$long_index, ui_get_full_url("images/image_problem.opaque.png"), "", $unit, $homeurl,
$water_mark, $config['fontpath'], $config['font_size'], $unit, $ttl,
$series_type, $chart_extra_data, $warning_min, $critical_min, $adapt_key, false, $series_suffix_str, $menu).
$series_type, $chart_extra_data, $warning_min, $critical_min, $adapt_key, false,
$series_suffix_str, $menu, $backgroundColor).
'<br>'.
area_graph($flash_chart, $chart_prev, $width, $height/2, $color_prev, $legend_prev,
$long_index_prev, ui_get_full_url("images/image_problem.opaque.png"), "", $unit, $homeurl,
$water_mark, $config['fontpath'], $config['font_size'], $unit, $ttl,
$series_type_prev, $chart_extra_data, $warning_min, $critical_min, $adapt_key, false, $series_suffix_str, $menu);
$series_type_prev, $chart_extra_data, $warning_min, $critical_min, $adapt_key, false,
$series_suffix_str, $menu, $backgroundColor);
}
else {
// Color commented not to restrict serie colors
return area_graph($flash_chart, $chart, $width, $height, $color, $legend,
$long_index, ui_get_full_url("images/image_problem.opaque.png"), "", $unit, $homeurl,
$water_mark, $config['fontpath'], $config['font_size'], $unit, $ttl,
$series_type, $chart_extra_data, $warning_min, $critical_min, $adapt_key, false, $series_suffix_str, $menu);
$series_type, $chart_extra_data, $warning_min, $critical_min, $adapt_key, false,
$series_suffix_str, $menu, $backgroundColor);
}
}
@ -856,7 +859,7 @@ function graphic_combined_module ($module_list, $weight_list, $period,
$width, $height, $title, $unit_name, $show_events = 0,
$show_alerts = 0, $pure = 0, $stacked = 0, $date = 0,
$only_image = false, $homeurl = '', $ttl = 1, $projection = false,
$prediction_period = false) {
$prediction_period = false, $background_color = 'white') {
global $config;
global $graphic_type;
@ -1292,7 +1295,8 @@ function graphic_combined_module ($module_list, $weight_list, $period,
$height, $color, $module_name_list, $long_index,
ui_get_full_url("images/image_problem.opaque.png"), "",
"", $homeurl, $water_mark, $config['fontpath'],
$fixed_font_size, "", $ttl);
$fixed_font_size, "", $ttl, array(), array(), 0, 0, '',
false, '', true, $background_color);
break;
default:
case CUSTOM_GRAPH_STACKED_AREA:
@ -1300,21 +1304,21 @@ function graphic_combined_module ($module_list, $weight_list, $period,
$width, $height, $color, $module_name_list, $long_index,
ui_get_full_url("images/image_problem.opaque.png"), "",
"", $water_mark, $config['fontpath'], $fixed_font_size,
"", $ttl, $homeurl);
"", $ttl, $homeurl, $background_color);
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.opaque.png"), "",
"", $water_mark, $config['fontpath'], $fixed_font_size,
"", $ttl, $homeurl);
"", $ttl, $homeurl, $background_color);
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.opaque.png"), "",
"", $water_mark, $config['fontpath'], $fixed_font_size,
"", $ttl, $homeurl);
"", $ttl, $homeurl, $background_color);
break;
}
}

View File

@ -219,11 +219,12 @@ function visual_map_print_item($layoutData) {
if ($layoutData['id_custom_graph'] != 0) {
$img = custom_graphs_print(
$layoutData['id_custom_graph'], $height, $width,
$period, null, true, 0, true);
$period, null, true, 0, true, $layoutData['image']);
}
else {
$img = grafico_modulo_sparse($id_module, $period, 0, $width,
$height, '', null, false, 1, false, 0, '', 0, 0, true, true);
$height, '', null, false, 1, false, 0, '', 0, 0, true, true,
'', 1, false, '', false, false, true, $layoutData['image']);
}
//Restore db connection
@ -1984,13 +1985,14 @@ function visual_map_print_visual_map ($id_layout, $show_links = true, $draw_line
$layout_data['id_custom_graph'],
$layout_data['height'],
$layout_data['width'],
$layout_data['period'], null, false, 0, true);
$layout_data['period'], null, false,
0, true, $layout_data['image']);
}
else {
else {
echo grafico_modulo_sparse ($layout_data['id_agente_modulo'], $layout_data['period'],
false, $layout_data['width'], $layout_data['height'],
'', null, false, 1, false, 0, '', 0, 0, true, true, $home_url, 1);
'', null, false, 1, false, 0, '', 0, 0, true, true, $home_url, 1, false, '', false,
false, true, $layout_data['image']);
}
//Restore db connection
if ($layout_data['id_metaconsole'] != 0) {

View File

@ -128,7 +128,18 @@ function visual_map_editor_print_item_palette($visualConsole_id, $background) {
'<td align="left" colspan="2" style="text-align: right;">' .
'<div id="preview" style="text-align: right;"></div></td>';
$form_items['background_color'] = array();
$form_items['background_color']['items'] = array(
'module_graph',
'datos');
$form_items['background_color']['html'] = '<td align="left"><span>' .
__('Background color') . '</span></td>
<td align="left">'. html_print_select (
array ('white' => __('White'),
'black' => __('Black'),
'transparent' => __('Transparent')),
'background_color', '', '', 0, 'white', true, false, false) . '</td>';
$form_items['radio_choice_graph'] = array();
$form_items['radio_choice_graph']['items'] = array(
'module_graph',

View File

@ -200,7 +200,7 @@ function area_graph($flash_chart, $chart_data, $width, $height, $color, $legend,
$long_index, $no_data_image, $xaxisname = "", $yaxisname = "", $homeurl="",
$water_mark = "", $font = '', $font_size = '', $unit = '', $ttl = 1, $series_type = array(),
$chart_extra_data = array(), $yellow_threshold = 0, $red_threshold = 0, $adapt_key = '', $force_integer = false,
$series_suffix_str = '', $menu = true) {
$series_suffix_str = '', $menu = true, $backgroundColor = 'white') {
setup_watermark($water_mark, $water_mark_file, $water_mark_url);
@ -250,6 +250,7 @@ function area_graph($flash_chart, $chart_data, $width, $height, $color, $legend,
$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);
@ -260,7 +261,8 @@ function area_graph($flash_chart, $chart_data, $width, $height, $color, $legend,
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 = '') {
$water_mark = "", $font = '', $font_size = '', $unit = '', $ttl = 1, $homeurl = '',
$backgroundColor = 'white') {
setup_watermark($water_mark, $water_mark_file, $water_mark_url);
@ -286,6 +288,7 @@ function stacked_area_graph($flash_chart, $chart_data, $width, $height, $color,
$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);
@ -295,7 +298,8 @@ function stacked_area_graph($flash_chart, $chart_data, $width, $height, $color,
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 = '') {
$water_mark = "", $font = '', $font_size = '', $unit = '', $ttl = 1, $homeurl = '',
$backgroundColor = 'white') {
setup_watermark($water_mark, $water_mark_file, $water_mark_url);
@ -322,7 +326,8 @@ function stacked_line_graph($flash_chart, $chart_data, $width, $height, $color,
$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 . "' />";
@ -331,7 +336,8 @@ function stacked_line_graph($flash_chart, $chart_data, $width, $height, $color,
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 = '') {
$water_mark = "", $font = '', $font_size = '', $unit = '', $ttl = 1, $homeurl = '',
$backgroundColor = 'white') {
setup_watermark($water_mark, $water_mark_file, $water_mark_url);
@ -354,7 +360,8 @@ function line_graph($flash_chart, $chart_data, $width, $height, $color, $legend,
$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 . "' />";

View File

@ -96,6 +96,11 @@ if (isset($graph['font_size'])) {
$font_size = $graph['font_size'];
}
}
if (isset($graph['backgroundColor'])) {
if (!empty($graph['backgroundColor'])) {
$backgroundColor = $graph['backgroundColor'];
}
}
if (isset($graph['antialiasing'])) {
$antialiasing = $graph['antialiasing'];
}
@ -302,7 +307,7 @@ switch($graph_type) {
case 'line':
pch_vertical_graph($graph_type, $data_keys, $data_values, $width,
$height, $rgb_color, $xaxisname, $yaxisname, false, $legend,
$font, $antialiasing, $water_mark, $font_size);
$font, $antialiasing, $water_mark, $font_size, $backgroundColor);
break;
case 'threshold':
pch_threshold_graph($graph_type, $data_keys, $data_values, $width,
@ -619,7 +624,8 @@ function pch_bar_graph ($graph_type, $index, $data, $width, $height, $font,
function pch_vertical_graph ($graph_type, $index, $data, $width, $height,
$rgb_color = false, $xaxisname = "", $yaxisname = "", $show_values = false,
$legend = array(), $font, $antialiasing, $water_mark = '', $font_size) {
$legend = array(), $font, $antialiasing, $water_mark = '', $font_size,
$backgroundColor = 'white') {
/* CAT:Vertical Charts */
if (!is_array($legend) || empty($legend)) {
@ -692,9 +698,24 @@ function pch_vertical_graph ($graph_type, $index, $data, $width, $height,
$MyData->addPoints($index,"Xaxis");
$MyData->setSerieDescription("Xaxis", $xaxisname);
$MyData->setAbscissa("Xaxis");
switch($backgroundColor) {
case 'white':
$transparent = false;
$fontColor = array('R' => 0, 'G' => 0, 'B' => 0);
break;
case 'black':
$transparent = false;
$fontColor = array('R' => 200, 'G' => 200, 'B' => 200);
break;
case 'transparent':
$transparent = true;
$fontColor = array('R' => 0, 'G' => 0, 'B' => 0);
break;
}
/* Create the pChart object */
$myPicture = new pImage($width,$height,$MyData);
$myPicture = new pImage($width,$height,$MyData,$transparent,$backgroundColor,$fontColor);
/* Turn of Antialiasing */
$myPicture->Antialias = $antialiasing;
@ -817,6 +838,15 @@ function pch_vertical_graph ($graph_type, $index, $data, $width, $height,
"XMargin" => 0,
"MinDivHeight" => 20,
"TicksFontSize" => $font_size - 1);
if (true) {
$scaleSettings['AxisR'] = '200';
$scaleSettings['AxisG'] = '200';
$scaleSettings['AxisB'] = '200';
$scaleSettings['TickR'] = '200';
$scaleSettings['TickG'] = '200';
$scaleSettings['TickB'] = '200';
}
$myPicture->drawScale($scaleSettings);
/* Turn on shadow computing */

View File

@ -62,9 +62,12 @@
var $DataSet = NULL; // Attached dataset
/* Class constructor */
function pImage($XSize,$YSize,$DataSet=NULL,$TransparentBackground=FALSE)
function pImage($XSize,$YSize,$DataSet=NULL,$TransparentBackground=FALSE, $ColorBackground = 'white', $FontColor = array('R' => 0, 'G' => 0, 'B' => 0))
{
$this->TransparentBackground = $TransparentBackground;
$this->FontColorR = $FontColor['R'];
$this->FontColorG = $FontColor['G'];
$this->FontColorB = $FontColor['B'];
if ( $DataSet != NULL ) { $this->DataSet = $DataSet; }
@ -81,8 +84,16 @@
}
else
{
$C_White = $this->AllocateColor($this->Picture,255,255,255);
imagefilledrectangle($this->Picture,0,0,$XSize,$YSize,$C_White);
switch($ColorBackground) {
case 'black':
$C = $this->AllocateColor($this->Picture,0,0,0);
break;
case 'white':
default:
$C = $this->AllocateColor($this->Picture,255,255,255);
break;
}
imagefilledrectangle($this->Picture,0,0,$XSize,$YSize,$C);
}
}
@ -240,4 +251,4 @@
function printDataSet()
{ print_r($this->DataSet); }
}
?>
?>