From 46e39e9f68950f5d21d1a3fcd8850319d86894c2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jos=C3=A9=20Gonz=C3=A1lez?= Date: Fri, 29 Apr 2022 12:36:01 +0200 Subject: [PATCH 1/3] Set better visual style for show top-n widgets --- .../include/lib/Dashboard/Widgets/top_n.php | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/pandora_console/include/lib/Dashboard/Widgets/top_n.php b/pandora_console/include/lib/Dashboard/Widgets/top_n.php index 24845cec87..7859ae7d86 100644 --- a/pandora_console/include/lib/Dashboard/Widgets/top_n.php +++ b/pandora_console/include/lib/Dashboard/Widgets/top_n.php @@ -454,11 +454,17 @@ class TopNWidget extends Widget } $data_hbar = []; + $valueMax = 0; + $valueMin = 0; foreach ($modules as $module) { $module['aliasAgent'] = ui_print_truncate_text($module['aliasAgent'], 20); - $item_name = ''; $item_name = $module['aliasAgent'].' - '.$module['nameModule']; $data_hbar[$item_name]['g'] = $module[$display]; + // Calculation of max-min values for show in graph. + $calc = (ceil((5 * (float) $module[$display]) / 100) + $module[$display]); + // Set of max-min values for graph. + $valueMax = ((int) $module[$display] >= $valueMax) ? $calc : $valueMax; + $valueMin = ((int) $module[$display] <= $valueMin) ? $calc : $valueMin; } $height = (count($data_hbar) * 25 + 35); @@ -480,7 +486,9 @@ class TopNWidget extends Widget 1, $config['homeurl'], 'white', - 'black' + 'black', + $valueMin, + $valueMax ); $output .= ''; From 118b845fa0aaf18385bad912807d95b5684efe20 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jos=C3=A9=20Gonz=C3=A1lez?= Date: Fri, 29 Apr 2022 12:49:01 +0200 Subject: [PATCH 2/3] Fix issue with equal values --- pandora_console/include/lib/Dashboard/Widgets/top_n.php | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/pandora_console/include/lib/Dashboard/Widgets/top_n.php b/pandora_console/include/lib/Dashboard/Widgets/top_n.php index 7859ae7d86..6116193539 100644 --- a/pandora_console/include/lib/Dashboard/Widgets/top_n.php +++ b/pandora_console/include/lib/Dashboard/Widgets/top_n.php @@ -463,8 +463,13 @@ class TopNWidget extends Widget // Calculation of max-min values for show in graph. $calc = (ceil((5 * (float) $module[$display]) / 100) + $module[$display]); // Set of max-min values for graph. - $valueMax = ((int) $module[$display] >= $valueMax) ? $calc : $valueMax; - $valueMin = ((int) $module[$display] <= $valueMin) ? $calc : $valueMin; + $valueMax = ((int) $module[$display] >= $valueMax) ? $calc : (int) $valueMax; + $valueMin = ((int) $module[$display] < $valueMin) ? $calc : (int) $valueMin; + } + + // This change is for get more space between values. + if ((int) $valueMax === (int) $valueMin) { + $valueMax += 10; } $height = (count($data_hbar) * 25 + 35); From b1c87d6a4037c99e0deae9f22dbefe6937ba9113 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jos=C3=A9=20Gonz=C3=A1lez?= Date: Wed, 11 May 2022 17:37:57 +0200 Subject: [PATCH 3/3] Minor fix for show better only booleans modules --- .../include/lib/Dashboard/Widgets/top_n.php | 20 +++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-) diff --git a/pandora_console/include/lib/Dashboard/Widgets/top_n.php b/pandora_console/include/lib/Dashboard/Widgets/top_n.php index 6116193539..993f611c8f 100644 --- a/pandora_console/include/lib/Dashboard/Widgets/top_n.php +++ b/pandora_console/include/lib/Dashboard/Widgets/top_n.php @@ -456,6 +456,15 @@ class TopNWidget extends Widget $data_hbar = []; $valueMax = 0; $valueMin = 0; + $booleanModulesCount = 0; + $booleanModulesTypes = [ + 2, + 6, + 9, + 18, + 35, + ]; + foreach ($modules as $module) { $module['aliasAgent'] = ui_print_truncate_text($module['aliasAgent'], 20); $item_name = $module['aliasAgent'].' - '.$module['nameModule']; @@ -465,10 +474,17 @@ class TopNWidget extends Widget // Set of max-min values for graph. $valueMax = ((int) $module[$display] >= $valueMax) ? $calc : (int) $valueMax; $valueMin = ((int) $module[$display] < $valueMin) ? $calc : (int) $valueMin; + // Count if all modules are booleans (for visual representation). + if (in_array($module['type_module'], $booleanModulesTypes) === true) { + $booleanModulesCount++; + } } - // This change is for get more space between values. - if ((int) $valueMax === (int) $valueMin) { + if ($booleanModulesCount === count($modules)) { + // All modules are booleans. By this, only are allowed 0 or 1. + $valueMax = 1; + } else if ((int) $valueMax === (int) $valueMin) { + // This change is for get more space between values. $valueMax += 10; }