From 8de1e7b218a769f63339cb2b3851e9203ee9b966 Mon Sep 17 00:00:00 2001 From: Pablo Aragon Date: Fri, 12 Apr 2024 13:11:37 +0200 Subject: [PATCH] 13402-Fix margins in widget Basic chart --- .../include/graphs/functions_flot.php | 8 ++++++- .../lib/Dashboard/Widgets/BasicChart.php | 21 +++++++++++++++++-- 2 files changed, 26 insertions(+), 3 deletions(-) diff --git a/pandora_console/include/graphs/functions_flot.php b/pandora_console/include/graphs/functions_flot.php index 329e515f06..0f0c2a86aa 100644 --- a/pandora_console/include/graphs/functions_flot.php +++ b/pandora_console/include/graphs/functions_flot.php @@ -303,9 +303,15 @@ function flot_area_graph( } } + $extra_styles = ''; + if (isset($params['extra_styles']) === true && empty($params['extra_styles']) === false) { + $extra_styles = $params['extra_styles']; + } + $return .= 'graph'.$params['adapt_key']."' style='".$width.'; - height: '.$params['height']."px;'>"; + height: '.$params['height'].'px; + '.$extra_styles."'>"; $legend_top = 10; if (empty($params['show_legend']) === false) { diff --git a/pandora_console/include/lib/Dashboard/Widgets/BasicChart.php b/pandora_console/include/lib/Dashboard/Widgets/BasicChart.php index a140d7fcb4..0910f0ba68 100644 --- a/pandora_console/include/lib/Dashboard/Widgets/BasicChart.php +++ b/pandora_console/include/lib/Dashboard/Widgets/BasicChart.php @@ -641,12 +641,28 @@ class BasicChart extends Widget $this->values['period'] = parent::getPeriod(); } + $margin = 10; + $size['height'] -= $margin; + $graph_height = $size['height']; + $margin_top = 0; + if ((bool) $this->values['showLabel'] === true) { + $margin_top = $this->values['sizeLabel']; + } + + if ((bool) $this->values['showValue'] === true) { + if ($this->values['sizeValue'] > $this->values['sizeLabel']) { + $margin_top = $this->values['sizeValue']; + } + } + + $graph_height -= $margin_top; + $params = [ 'agent_module_id' => $this->values['moduleId'], 'period' => $this->values['period'], 'show_events' => false, 'width' => '100%', - 'height' => $size['height'], + 'height' => $graph_height, 'title' => $module_name, 'unit' => $units_name, 'only_image' => false, @@ -661,6 +677,7 @@ class BasicChart extends Widget 'backgroundColor' => 'transparent', // 'server_id' => $metaconsoleId, 'basic_chart' => true, + 'extra_styles' => 'bottom: -'.($margin_top + $margin - 1).'px; margin-left: 0px;', 'array_colors' => [ [ 'border' => '#000000', @@ -671,7 +688,7 @@ class BasicChart extends Widget ]; $graph = \grafico_modulo_sparse($params); - $output = '
'; + $output = '
'; if (str_contains($graph, 'values['colorLabel'].'; font-size:'.$this->values['sizeLabel'].'px;">';