New networkmaps in progress... (Fixed problems in Open part)

This commit is contained in:
Arturo Gonzalez 2016-09-21 09:52:42 +02:00
parent c643e2bce0
commit cbef0f3dfd
4 changed files with 113 additions and 91 deletions

View File

@ -1127,6 +1127,38 @@ function networkmap_generate_dot ($pandora_name, $group = 0,
$graph = networkmap_open_graph ($layout, $nooverlap, $pure, $zoom,
$ranksep, $font_size, $size_canvas);
//The orphans
if ($l2_network || $old_mode) {
$count = 0;
$group_nodes = 10;
$graph .= networkmap_create_transparent_node($count);
foreach (array_keys($networkmap_data['orphans']) as $node) {
if ($group_nodes == 0) {
$count++;
$graph .= networkmap_create_transparent_node($count);
$group_nodes = 10;
}
$graph .= networkmap_create_transparent_edge('transp_' . $count,
$node);
$group_nodes--;
}
}
else {
// Create a central node if orphan nodes exist
if (count ($networkmap_data['$orphans']) || empty ($nodes)) {
$graph .= networkmap_create_pandora_node ($pandora_name, $font_size, $simple, $stats);
}
// Define edges for orphan nodes
foreach (array_keys($networkmap_data['orphans']) as $node) {
$graph .= networkmap_create_edge ('0', $node, $layout, $nooverlap, $pure, $zoom, $ranksep, $simple, $regen, $font_size, $group, 'operation/agentes/networkmap', 'topology', $id_networkmap);
}
}
// Create nodes
foreach ($networkmap_data['nodes'] as $node_id => $node) {
switch ($node['type']) {
@ -1183,37 +1215,6 @@ function networkmap_generate_dot ($pandora_name, $group = 0,
}
}
//The orphans
if ($l2_network || $old_mode) {
$count = 0;
$group_nodes = 10;
$graph .= networkmap_create_transparent_node($count);
foreach (array_keys($networkmap_data['orphans']) as $node) {
if ($group_nodes == 0) {
$count++;
$graph .= networkmap_create_transparent_node($count);
$group_nodes = 10;
}
$graph .= networkmap_create_transparent_edge('transp_' . $count,
$node);
$group_nodes--;
}
}
else {
// Create a central node if orphan nodes exist
if (count ($networkmap_data['$orphans']) || empty ($nodes)) {
$graph .= networkmap_create_pandora_node ($pandora_name, $font_size, $simple, $stats);
}
// Define edges for orphan nodes
foreach (array_keys($networkmap_data['orphans']) as $node) {
$graph .= networkmap_create_edge ('0', $node, $layout, $nooverlap, $pure, $zoom, $ranksep, $simple, $regen, $font_size, $group, 'operation/agentes/networkmap', 'topology', $id_networkmap);
}
}
// Close graph
$graph .= networkmap_close_graph ();

View File

@ -178,32 +178,36 @@ function networkmap_process_networkmap($id = 0) {
}
else {
$nodes_and_relations['nodes'] = array();
$index = 0;
foreach ($nodes as $key => $node) {
$nodes_and_relations['nodes'][]['id_map'] = $id;
$nodes_and_relations['nodes'][]['x'] = (int)$node['coords'][0];
$nodes_and_relations['nodes'][]['y'] = (int)$node['coords'][1];
$nodes_and_relations['nodes'][]['type'] = $node['type'];
$nodes_and_relations['nodes'][$index]['id_map'] = $id;
$nodes_and_relations['nodes'][$index]['x'] = (int)$node['coords'][0];
$nodes_and_relations['nodes'][$index]['y'] = (int)$node['coords'][1];
$nodes_and_relations['nodes'][$index]['type'] = $node['type'];
$style['shape'] = 'circle';
$style['image'] = $node['image'];
$style['width'] = $node['width'];
$style['height'] = $node['height'];
$style['label'] = $node['text'];
$nodes_and_relations['nodes'][]['style'] = json_encode($style);
$nodes_and_relations['nodes'][$index]['style'] = json_encode($style);
if ($node['type'] == 'agent') {
$nodes_and_relations['nodes'][]['source_data'] = $node['id_agent'];
$nodes_and_relations['nodes'][$index]['source_data'] = $node['id_agent'];
}
else {
$nodes_and_relations['nodes'][]['source_data'] = $node['id_module'];
$nodes_and_relations['nodes'][$index]['source_data'] = $node['id_module'];
}
$index++;
}
$index = 0;
$nodes_and_relations['relations'] = array();
foreach ($relation_nodes as $relation) {
$nodes_and_relations['relations'][]['id_map'] = $id;
$nodes_and_relations['relations'][]['id_parent'] = $array_key_to_db_id[$relation['parent']];
$nodes_and_relations['relations'][]['id_child'] = $array_key_to_db_id[$relation['child']];
$nodes_and_relations['relations'][]['parent_type'] = $relation['parent_type'];
$nodes_and_relations['relations'][]['child_type'] = $relation['child_type'];
$nodes_and_relations['relations'][$index]['id_map'] = $id;
$nodes_and_relations['relations'][$index]['id_parent'] = $relation['id_parent'];
$nodes_and_relations['relations'][$index]['id_child'] = $relation['id_child'];
$nodes_and_relations['relations'][$index]['parent_type'] = $relation['parent_type'];
$nodes_and_relations['relations'][$index]['child_type'] = $relation['child_type'];
$index++;
}
$center = array('x' => 500, 'y' => 500);
@ -450,13 +454,22 @@ function networkmap_links_to_js_links($relations, $nodes_graph) {
$item['id_module_start'] = $id_source;
$item['text_start'] = io_safe_output(modules_get_agentmodule_name($item['id_module_start']));
}
foreach ($nodes_graph as $node) {
if ($node['id_db'] == $relation['id_parent']) {
$item['target'] = $node['id'];
if (enterprise_installed()) {
if ($node['id_db'] == $relation['id_parent']) {
$item['target'] = $node['id'];
}
if ($node['id_db'] == $relation['id_child']) {
$item['source'] = $node['id'];
}
}
if ($node['id_db'] == $relation['id_child']) {
$item['source'] = $node['id'];
else {
if ($node['id'] == $relation['id_parent']) {
$item['target'] = $node['id'];
}
else if ($node['id'] == $relation['id_child']) {
$item['source'] = $node['id'];
}
}
}
@ -471,6 +484,8 @@ function networkmap_write_js_array($id, $nodes_and_relations = array()) {
db_clean_cache();
$ent_installed = (int)enterprise_installed();
$networkmap = db_get_row('tmap', 'id', $id);
$networkmap['filter'] = json_decode($networkmap['filter'], true);
@ -497,7 +512,7 @@ function networkmap_write_js_array($id, $nodes_and_relations = array()) {
$networkmap['width'] . ", " .
$networkmap['height'] . "];\n";
echo "var enterprise_installed = " . enterprise_installed() . ";\n";
echo "var enterprise_installed = " . $ent_installed . ";\n";
echo "var networkmap_holding_area_dimensions = " .
json_encode($networkmap['filter']['holding_area']) . ";\n";
@ -519,6 +534,7 @@ function networkmap_write_js_array($id, $nodes_and_relations = array()) {
$count_item_holding_area = 0;
$count = 0;
$nodes_graph = array();
foreach ($nodes as $key => $node) {
$style = json_decode($node['style'], true);
$node['style'] = json_decode($node['style'], true);
@ -1070,7 +1086,6 @@ function show_networkmap($id = 0, $user_readonly = false, $nodes_and_relations =
<script type="text/javascript">
<?php
networkmap_write_js_array($id, $nodes_and_relations);
?>
////////////////////////////////////////////////////////////////////////
// document ready

View File

@ -30,7 +30,6 @@ function draw_minimap() {
context_minimap.fill();
});
//Draw the rect of viewport
context_minimap.beginPath();
context_minimap.strokeStyle = "#f00";
@ -1375,6 +1374,14 @@ function show_menu(item, data) {
items_list["add_node"] = {
name: add_node_menu,
icon: "add_node",
disabled : function() {
if (enterprise_installed) {
return false;
}
else {
return true;
}
},
"callback": function(key, options) {
add_node();
}
@ -1824,9 +1831,7 @@ function add_fictional_node() {
}
}
function init_graph(parameter_object) {
console.log(parameter_object);
function init_graph(parameter_object) {
window.width_svg = $("#networkconsole").width();
if ($("#main").height()) {
window.height_svg = $("#main").height();
@ -2142,43 +2147,44 @@ function init_graph(parameter_object) {
"stroke-dasharray: none;")
.on("contextmenu", function(d) { show_menu("background", d);});
if (enterprise_installed) {
window.layer_graph.append("rect")
.attr("id", "holding_area")
.attr("width", holding_area_dimensions[0])
.attr("height", holding_area_dimensions[1])
.attr("x",
networkmap_dimensions[0] + node_radius - holding_area_dimensions[0])
.attr("y",
networkmap_dimensions[1] + node_radius - holding_area_dimensions[1])
.attr("style", "fill: #ddd; " +
"fill-opacity: 0.75; " +
"stroke: #00ff00; " +
"stroke-width: 4; " +
"stroke-miterlimit: 4; " +
"stroke-opacity: 1; " +
"stroke-dasharray: none; " +
"stroke-dasharray: 12,3; " +
"stroke-dashoffset: 0");
window.layer_graph.append("rect")
.attr("id", "holding_area")
.attr("width", holding_area_dimensions[0])
.attr("height", holding_area_dimensions[1])
.attr("x",
networkmap_dimensions[0] + node_radius - holding_area_dimensions[0])
.attr("y",
networkmap_dimensions[1] + node_radius - holding_area_dimensions[1])
.attr("style", "fill: #ddd; " +
"fill-opacity: 0.75; " +
"stroke: #00ff00; " +
"stroke-width: 4; " +
"stroke-miterlimit: 4; " +
"stroke-opacity: 1; " +
"stroke-dasharray: none; " +
"stroke-dasharray: 12,3; " +
"stroke-dashoffset: 0");
window.layer_graph.append("text")
.append("tspan")
.attr("xml:space", "preserve")
.attr("style", "font-size: 32px; " +
"font-style: normal; " +
"font-weight: normal; " +
"text-align: start; " +
"line-height: 125%; " +
"letter-spacing: 0px; " +
"word-spacing: 0px; " +
"text-anchor: start; " +
"fill: #000000; " +
"fill-opacity: 1; " +
"stroke: none; " +
"font-family: Sans")
.attr("x", networkmap_dimensions[0] + node_radius - holding_area_dimensions[0])
.attr("y", networkmap_dimensions[1] + node_radius - holding_area_dimensions[1])
.text(holding_area_title);
window.layer_graph.append("text")
.append("tspan")
.attr("xml:space", "preserve")
.attr("style", "font-size: 32px; " +
"font-style: normal; " +
"font-weight: normal; " +
"text-align: start; " +
"line-height: 125%; " +
"letter-spacing: 0px; " +
"word-spacing: 0px; " +
"text-anchor: start; " +
"fill: #000000; " +
"fill-opacity: 1; " +
"stroke: none; " +
"font-family: Sans")
.attr("x", networkmap_dimensions[0] + node_radius - holding_area_dimensions[0])
.attr("y", networkmap_dimensions[1] + node_radius - holding_area_dimensions[1])
.text(holding_area_title);
}
window.layer_graph_links = window.layer_graph
.append("g")

View File

@ -17,7 +17,7 @@ global $config;
check_login();
require_once ('include/functions_pandora_networkmap.php');
require_once ('enterprise/include/functions_policies.php');
enterprise_include_once('include/functions_policies.php');
require_once ('include/functions_modules.php');
//--------------INIT AJAX-----------------------------------------------