Merge branch 'ent-8892-Widget-TopN-sale-mal' into 'develop'

Set better visual style for show top-n widgets

See merge request artica/pandorafms!4851
This commit is contained in:
Daniel Rodriguez 2022-05-12 10:18:06 +00:00
commit e7a136e5f5
1 changed files with 31 additions and 2 deletions

View File

@ -454,11 +454,38 @@ 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 = '';
$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 : (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++;
}
}
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;
}
$height = (count($data_hbar) * 25 + 35);
@ -480,7 +507,9 @@ class TopNWidget extends Widget
1,
$config['homeurl'],
'white',
'#DFDFDF'
'#DFDFDF',
$valueMin,
$valueMax
);
$output .= '</div>';