2014-07-30 Alejandro Gallardo <alejandro.gallardo@artica.es>
* include/functions_graph.php: Finished the function "graph_monitor_wheel". This function returns a sunburst graph representing all the group>agent>module group>module hierarchy. * include/functions_groups.php: Added the function "groups_get_tree". This function returns an array representing the group hierarchy of the passed groups array. * include/graphs/pandora.d3.js: Improved the function "sunburst". Now this graph can show tooltips. git-svn-id: https://svn.code.sf.net/p/pandora/code/trunk@10366 c3f86ba8-e40f-0410-aaad-9ba5e7f4b01f
This commit is contained in:
parent
478d521f59
commit
798d099f98
|
@ -1,3 +1,17 @@
|
|||
2014-07-30 Alejandro Gallardo <alejandro.gallardo@artica.es>
|
||||
|
||||
* include/functions_graph.php: Finished the function
|
||||
"graph_monitor_wheel". This function returns a sunburst
|
||||
graph representing all the group>agent>module group>module
|
||||
hierarchy.
|
||||
|
||||
* include/functions_groups.php: Added the function
|
||||
"groups_get_tree". This function returns an array representing
|
||||
the group hierarchy of the passed groups array.
|
||||
|
||||
* include/graphs/pandora.d3.js: Improved the function
|
||||
"sunburst". Now this graph can show tooltips.
|
||||
|
||||
2014-07-30 Miguel de Dios <miguel.dedios@artica.es>
|
||||
|
||||
* godmode/servers/manage_recontask.php,
|
||||
|
|
|
@ -4091,47 +4091,157 @@ function graph_snmp_traps_treemap ($data, $width = 700, $height = 700) {
|
|||
/**
|
||||
* Print a solarburst graph with a representation of all the groups, agents, module groups and modules grouped
|
||||
*/
|
||||
function graph_monitor_wheel ($data, $unit, $width = 700, $height = 700) {
|
||||
function graph_monitor_wheel ($width = 500, $height = 600) {
|
||||
global $config;
|
||||
|
||||
$data = array();
|
||||
|
||||
include_once ($config['homedir'] . "/include/functions_users.php");
|
||||
//include_once ($config['homedir'] . "/include/functions_groups.php");
|
||||
include_once ($config['homedir'] . "/include/functions_groups.php");
|
||||
include_once ($config['homedir'] . "/include/functions_agents.php");
|
||||
//include_once ($config['homedir'] . "/include/functions_modules.php");
|
||||
|
||||
$graph_data = array();
|
||||
|
||||
$groups = users_get_groups(false, "AR", false, true);
|
||||
|
||||
$data_groups = array();
|
||||
if (!empty($groups)) {
|
||||
$groups_aux = $groups;
|
||||
$data_groups = groups_get_tree($groups_aux);
|
||||
$groups_aux = $groups = null;
|
||||
}
|
||||
|
||||
if (!empty($data_groups)) {
|
||||
$filter = array('id_grupo' => array_keys($groups));
|
||||
$fields = array('id_agente', 'id_parent', 'id_grupo', 'nombre');
|
||||
$agents = agents_get_agents($filter, $fields);
|
||||
|
||||
if (!empty($agents)) {
|
||||
$agents_id = array();
|
||||
$agents_aux = array();
|
||||
foreach ($agents as $key => $agent) {
|
||||
$agents_id[] = $agent['id_agente'];
|
||||
$agents_aux[$agent['id_agente']] = $agent;
|
||||
}
|
||||
$agents = $agents_aux;
|
||||
$agents_aux = null;
|
||||
$fields = array('id_agente_modulo', 'id_agente', 'id_module_group', 'nombre');
|
||||
|
||||
$module_groups = modules_get_modulegroups();
|
||||
$modules = agents_get_modules($agents_id, $fields);
|
||||
$module_groups[0] = __('Not assigned');
|
||||
$modules = agents_get_modules(array_keys($agents), $fields);
|
||||
|
||||
$data_agents = array();
|
||||
if (!empty($modules)) {
|
||||
|
||||
foreach ($modules as $key => $module) {
|
||||
$module_id = $module['id_agente_modulo'];
|
||||
$agent_id = $module['id_agente'];
|
||||
$module_group_id = $module['id_module_group'];
|
||||
$module_name = $module['nombre'];
|
||||
|
||||
if (!isset($data_agents[$agent_id])) {
|
||||
$data_agents[$agent_id] = array();
|
||||
$data_agents[$agent_id]['id'] = $agent_id;
|
||||
$data_agents[$agent_id]['name'] = $agents[$agent_id]['nombre'];
|
||||
$data_agents[$agent_id]['group'] = $agents[$agent_id]['id_grupo'];
|
||||
$data_agents[$agent_id]['type'] = 'agent';
|
||||
$data_agents[$agent_id]['size'] = 30;
|
||||
$data_agents[$agent_id]['children'] = array();
|
||||
|
||||
$tooltip_content = __('Agent') . ": <b>" . $data_agents[$agent_id]['name'] . "</b>";
|
||||
$data_agents[$agent_id]['tooltip_content'] = $tooltip_content;
|
||||
|
||||
unset($agents[$agent_id]);
|
||||
}
|
||||
if (!isset($data_agents[$agent_id]['children'][$module_group_id])) {
|
||||
$data_agents[$agent_id]['children'][$module_group_id] = array();
|
||||
$data_agents[$agent_id]['children'][$module_group_id]['id'] = $module_group_id;
|
||||
$data_agents[$agent_id]['children'][$module_group_id]['name'] = $module_groups[$module_group_id];
|
||||
$data_agents[$agent_id]['children'][$module_group_id]['type'] = 'module_group';
|
||||
$data_agents[$agent_id]['children'][$module_group_id]['size'] = 10;
|
||||
$data_agents[$agent_id]['children'][$module_group_id]['children'] = array();
|
||||
|
||||
$tooltip_content = __('Module group') . ": <b>" . $module_groups[$module_group_id] . "</b>";
|
||||
$data_agents[$agent_id]['children'][$module_group_id]['tooltip_content'] = $tooltip_content;
|
||||
}
|
||||
|
||||
$data_module = array();
|
||||
$data_module['id'] = $module_id;
|
||||
$data_module['name'] = $module_name;
|
||||
$data_module['type'] = 'module';
|
||||
$data_module['size'] = 10;
|
||||
|
||||
$tooltip_content = __('Module') . ": <b>" . $module_name . "</b>";
|
||||
$data_module['tooltip_content'] = $tooltip_content;
|
||||
|
||||
$data_agents[$agent_id]['children'][$module_group_id]['children'][] = $data_module;
|
||||
|
||||
unset($modules[$module_id]);
|
||||
}
|
||||
}
|
||||
foreach ($agents as $id => $agent) {
|
||||
if (!isset($data_agents[$id])) {
|
||||
$data_agents[$id] = array();
|
||||
$data_agents[$id]['id'] = $id;
|
||||
$data_agents[$id]['name'] = $agent['name'];
|
||||
$data_agents[$id]['type'] = 'agent';
|
||||
}
|
||||
}
|
||||
$agents = null;
|
||||
}
|
||||
}
|
||||
|
||||
function iterate_group_array ($groups, &$data_agents) {
|
||||
|
||||
$data = array();
|
||||
|
||||
if (empty ($data)) {
|
||||
return fs_error_image ();
|
||||
foreach ($groups as $id => $group) {
|
||||
|
||||
$group_aux = array();
|
||||
$group_aux['id'] = $id;
|
||||
$group_aux['name'] = $group['nombre'];
|
||||
$group_aux['parent'] = $group['parent'];
|
||||
$group_aux['type'] = 'group';
|
||||
$group_aux['size'] = 100;
|
||||
|
||||
$tooltip_content = __('Group') . ": <b>" . $group_aux['name'] . "</b>";
|
||||
$group_aux['tooltip_content'] = $tooltip_content;
|
||||
|
||||
if (!isset($group['children']))
|
||||
$group_aux['children'] = array();
|
||||
if (!empty($group['children']))
|
||||
$group_aux['children'] = iterate_group_array($group['children']);
|
||||
|
||||
$agents = extract_agents_with_group_id($data_agents, $id);
|
||||
|
||||
if (!empty($agents))
|
||||
$group_aux['children'] = array_merge($group_aux['children'], $agents);
|
||||
|
||||
$data[] = $group_aux;
|
||||
}
|
||||
|
||||
return $data;
|
||||
}
|
||||
|
||||
function extract_agents_with_group_id (&$agents, $group_id) {
|
||||
$valid_agents = array();
|
||||
foreach ($agents as $id => $agent) {
|
||||
if (isset($agent['group']) && $agent['group'] == $group_id) {
|
||||
$valid_agents[$id] = $agent;
|
||||
unset($agents[$id]);
|
||||
}
|
||||
}
|
||||
if (!empty($valid_agents))
|
||||
return $valid_agents;
|
||||
else
|
||||
return false;
|
||||
}
|
||||
|
||||
$graph_data = array('name' => __('Main node'), 'children' => iterate_group_array($data_groups, $data_agents));
|
||||
|
||||
if (empty($graph_data['children']))
|
||||
return fs_error_image();
|
||||
|
||||
include_once($config['homedir'] . "/include/graphs/functions_d3.php");
|
||||
|
||||
return d3_tree_map_graph ($data, $width, $height, true);
|
||||
return d3_sunburst_graph ($graph_data, $width, $height, true);
|
||||
}
|
||||
|
||||
?>
|
||||
|
|
|
@ -1531,4 +1531,42 @@ function groups_print_group_sons($group, $sons, &$branch_classes, $groups_count,
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Return an array with the groups hierarchy (Recursive)
|
||||
*
|
||||
* @param array Groups array passed by reference
|
||||
* @param mixed The id of the parent to search or false to begin the search from the first hierarchy level
|
||||
*
|
||||
* @return array The groups reordered by its hierarchy
|
||||
*/
|
||||
function groups_get_tree(&$groups, $parent = false) {
|
||||
$return = array();
|
||||
|
||||
foreach ($groups as $id => $group) {
|
||||
if ($parent === false && (!isset($group['parent']) || $group['parent'] == 0)) {
|
||||
$return[$id] = $group;
|
||||
unset($groups[$id]);
|
||||
$children = groups_get_tree($groups, $id);
|
||||
|
||||
if (!empty($children)) {
|
||||
$return[$id]['children'] = $children;
|
||||
}
|
||||
}
|
||||
else if ($parent && isset($group['parent']) && $group['parent'] == $parent) {
|
||||
$return[$id] = $group;
|
||||
unset($groups[$id]);
|
||||
$children = groups_get_tree($groups, $id);
|
||||
|
||||
if (!empty($children)) {
|
||||
$return[$id]['children'] = $children;
|
||||
}
|
||||
}
|
||||
else {
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
||||
return $return;
|
||||
}
|
||||
?>
|
||||
|
|
|
@ -716,7 +716,10 @@ function sunburst (recipient, data, width, height) {
|
|||
.enter().append("path")
|
||||
.attr("d", arc)
|
||||
.style("fill", function(d) { return color((d.children ? d : d.parent).name); })
|
||||
.on("click", click);
|
||||
.on("click", click)
|
||||
.on("mouseover", over_user)
|
||||
.on("mouseout", out_user)
|
||||
.on("mousemove", move_tooltip);
|
||||
|
||||
function click(d) {
|
||||
path.transition()
|
||||
|
@ -737,4 +740,68 @@ function sunburst (recipient, data, width, height) {
|
|||
: function(t) { x.domain(xd(t)); y.domain(yd(t)).range(yr(t)); return arc(d); };
|
||||
};
|
||||
}
|
||||
|
||||
function move_tooltip(d) {
|
||||
var x = d3.event.pageX + 10;
|
||||
var y = d3.event.pageY + 10;
|
||||
|
||||
$("#tooltip").css('left', x + 'px');
|
||||
$("#tooltip").css('top', y + 'px');
|
||||
}
|
||||
|
||||
function over_user(d) {
|
||||
id = d.id;
|
||||
|
||||
$("#" + id).css('border', '1px solid black');
|
||||
$("#" + id).css('z-index', '1');
|
||||
|
||||
show_tooltip(d);
|
||||
}
|
||||
|
||||
function out_user(d) {
|
||||
id = d.id;
|
||||
|
||||
$("#" + id).css('border', '');
|
||||
$("#" + id).css('z-index', '');
|
||||
|
||||
hide_tooltip();
|
||||
}
|
||||
|
||||
function create_tooltip(d, x, y) {
|
||||
var tooltip = (typeof d.tooltip_content != 'undefined') ? d.tooltip_content : d.name;
|
||||
|
||||
if ($("#tooltip").length == 0) {
|
||||
$(recipient)
|
||||
.append($("<div></div>")
|
||||
.attr('id', 'tooltip')
|
||||
.html(tooltip));
|
||||
}
|
||||
else {
|
||||
$("#tooltip").html(tooltip);
|
||||
}
|
||||
|
||||
$("#tooltip").attr('style', 'background: #fff;' +
|
||||
'position: absolute;' +
|
||||
'display: block;' +
|
||||
'width: 200px;' +
|
||||
'text-align: left;' +
|
||||
'padding: 10px 10px 10px 10px;' +
|
||||
'z-index: 2;' +
|
||||
"-webkit-box-shadow: 7px 7px 5px rgba(50, 50, 50, 0.75);" +
|
||||
"-moz-box-shadow: 7px 7px 5px rgba(50, 50, 50, 0.75);" +
|
||||
"box-shadow: 7px 7px 5px rgba(50, 50, 50, 0.75);" +
|
||||
'left: ' + x + 'px;' +
|
||||
'top: ' + y + 'px;');
|
||||
}
|
||||
|
||||
function show_tooltip(d) {
|
||||
var x = d3.event.pageX + 10;
|
||||
var y = d3.event.pageY + 10;
|
||||
|
||||
create_tooltip(d, x, y);
|
||||
}
|
||||
|
||||
function hide_tooltip() {
|
||||
$("#tooltip").hide();
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue