Added custom graphviz fields to map creation

This commit is contained in:
Arturo Gonzalez 2017-11-27 13:52:31 +01:00
parent 6b79dc357d
commit 192175a4cc
4 changed files with 179 additions and 7 deletions

View File

@ -254,7 +254,7 @@ function networkmap_generate_dot ($pandora_name, $group = 0,
$id_networkmap = 0, $show_snmp_modules = 0, $cut_names = true,
$relative = false, $text_filter = '', $ip_mask = null,
$dont_show_subgroups = false, $strict_user = false, $size_canvas = null,
$old_mode = false) {
$old_mode = false, $map_filter = array()) {
global $config;
$nooverlap = 1;
@ -361,7 +361,7 @@ function networkmap_generate_dot ($pandora_name, $group = 0,
// Open Graph
$graph = networkmap_open_graph ($layout, $nooverlap, $pure, $zoom,
$ranksep, $font_size, $size_canvas);
$ranksep, $font_size, $size_canvas, $map_filter);
// Parse agents
$nodes = array ();
@ -1396,7 +1396,7 @@ function networkmap_close_group () {
// Opens a graph definition
function networkmap_open_graph ($layout, $nooverlap, $pure, $zoom,
$ranksep, $font_size, $size_canvas) {
$ranksep, $font_size, $size_canvas, $map_filter = array()) {
global $config;
@ -1423,21 +1423,65 @@ function networkmap_open_graph ($layout, $nooverlap, $pure, $zoom,
$size = ($size_canvas['x'] / 100) . "," . ($size_canvas['y'] / 100);
}
// Graphviz custom values
if (isset($map_filter['node_sep'])) {
$node_sep = $map_filter['node_sep'];
}
else {
$node_sep = 0.25;
}
if (isset($map_filter['rank_sep'])) {
$rank_sep = $map_filter['rank_sep'];
}
else {
if ($layout == "radial") {
$rank_sep = 1.0;
}
else {
$rank_sep = 0.5;
}
}
if (isset($map_filter['mindist'])) {
$mindist = $map_filter['mindist'];
}
else {
$mindist = 1.0;
}
if (isset($map_filter['kval'])) {
$kval = $map_filter['kval'];
}
else {
$kval = 0.3;
}
// BEWARE: graphwiz DONT use single ('), you need double (")
$head = "graph networkmap { dpi=100; bgcolor=\"transparent\"; labeljust=l; margin=0; pad=\"0.75,0.75\";";
if ($nooverlap != '') {
$head .= "ranksep=\"4\";";
$head .= "overlap=\"false\";";
$head .= "outputorder=edgesfirst;";
}
if ($layout == 'flat' || $layout == 'spring1' || $layout == "spring2") {
if ($nooverlap != '') {
$head .= "overlap=\"scalexy\";";
}
if ($layout == 'flat') {
$head .= "ranksep=\"$rank_sep\";";
}
if ($layout == 'spring2') {
$head .= "K=\"$kval\";";
}
}
if ($layout == 'radial') {
$head .= "ranksep=\"$rank_sep\";";
}
if ($layout == 'circular') {
$head .= "mindist=\"$mindist\";";
}
$head .= "ratio=fill;";
$head .= "root=0;";
$head .= "nodesep=\"0.=2\";";
$head .= "nodesep=\"$node_sep\";";
$head .= "size=\"$size\";";
$head .= "\n";

View File

@ -231,7 +231,8 @@ function networkmap_process_networkmap($id = 0) {
$dont_show_subgroups,
false,
null,
$old_mode);
$old_mode,
$map_filter);
switch (PHP_OS) {
case "WIN32":

View File

@ -41,6 +41,10 @@ if ($new_networkmap) {
$offset_x = "";
$offset_y = "";
$scale_z = 0.5;
$node_sep = 0.25;
$rank_sep = 1.0;
$mindist = 1.0;
$kval = 0.3;
}
$disabled_generation_method_select = false;
@ -83,6 +87,36 @@ if ($edit_networkmap) {
$offset_y = $filter['y_offs'];
$scale_z = $filter['z_dash'];
if (isset($filter['node_sep'])) {
$node_sep = $filter['node_sep'];
}
else {
$node_sep = 0.25;
}
if (isset($filter['rank_sep'])) {
$rank_sep = $filter['rank_sep'];
}
else {
if ($values['generation_method'] == "twopi") {
$rank_sep = 1.0;
}
else {
$rank_sep = 0.5;
}
}
if (isset($filter['mindist'])) {
$mindist = $filter['mindist'];
}
else {
$mindist = 1.0;
}
if (isset($filter['kval'])) {
$kval = $filter['kval'];
}
else {
$kval = 0.3;
}
$node_radius = $filter['node_radius'];
$source = $values['source'];
@ -245,6 +279,18 @@ else {
'', '', 'twopi', true, false, true, '',
$disabled_generation_method_select);
$table->data['nodesep'][0] = __('Node separation');
$table->data['nodesep'][1] = html_print_input_text ('node_sep', $node_sep, '', 5, 10,true, $disabled_source) . ui_print_help_tip (__('Separation between nodes. By default 0.25'), true);
$table->data['ranksep'][0] = __('Rank separation');
$table->data['ranksep'][1] = html_print_input_text ('rank_sep', $rank_sep, '', 5, 10,true, $disabled_source) . ui_print_help_tip (__('Only flat and radial. Separation between arrows. By default 0.5 in flat and 1.0 in radial'), true);
$table->data['mindist'][0] = __('Min nodes dist');
$table->data['mindist'][1] = html_print_input_text ('mindist', $mindist, '', 5, 10,true, $disabled_source) . ui_print_help_tip (__('Only circular. Minimum separation between all nodes. By default 1.0'), true);
$table->data['kval'][0] = __('Default ideal node separation');
$table->data['kval'][1] = html_print_input_text ('kval', $kval, '', 5, 10,true, $disabled_source) . ui_print_help_tip (__('Only fdp. Default ideal node separation in the layout. By default 0.3'), true);
echo '<form method="post" action="index.php?sec=network&amp;sec2=operation/agentes/pandora_networkmap">';
html_print_table($table);
@ -297,6 +343,72 @@ $(document).ready(function() {
}
});
$("#method").on('change', function () {
var method = $("#method").val();
if (method == 'circo') {
$("#form_editor-ranksep")
.css('display', 'none');
$("#form_editor-mindist")
.css('display', '');
$("#form_editor-kval")
.css('display', 'none');
$("#form_editor-nodesep")
.css('display', '');
}
else if (method == 'dot') {
$("#form_editor-ranksep")
.css('display', '');
$("#form_editor-mindist")
.css('display', 'none');
$("#form_editor-kval")
.css('display', 'none');
$("#form_editor-nodesep")
.css('display', '');
}
else if (method == 'twopi') {
$("#form_editor-ranksep")
.css('display', '');
$("#form_editor-mindist")
.css('display', 'none');
$("#form_editor-kval")
.css('display', 'none');
$("#form_editor-nodesep")
.css('display', '');
}
else if (method == 'neato') {
$("#form_editor-ranksep")
.css('display', 'none');
$("#form_editor-mindist")
.css('display', 'none');
$("#form_editor-kval")
.css('display', 'none');
$("#form_editor-nodesep")
.css('display', '');
}
else if (method == 'radial_dinamic') {
$("#form_editor-ranksep")
.css('display', 'none');
$("#form_editor-mindist")
.css('display', 'none');
$("#form_editor-kval")
.css('display', 'none');
$("#form_editor-nodesep")
.css('display', 'none');
}
else if (method == 'fdp') {
$("#form_editor-ranksep")
.css('display', 'none');
$("#form_editor-mindist")
.css('display', 'none');
$("#form_editor-kval")
.css('display', '');
$("#form_editor-nodesep")
.css('display', '');
}
});
$("input[name='source']").trigger("change");
$("#method").trigger("change");
});
</script>

View File

@ -219,6 +219,16 @@ if ($new_networkmap || $save_networkmap) {
$offset_y = get_parameter('pos_y');
$scale_z = get_parameter('scale_z', 0.5);
$node_sep = get_parameter('node_sep', "0.25");
if ($method == "twopi") {
$rank_sep = get_parameter('rank_sep', "1.0");
}
else {
$rank_sep = get_parameter('rank_sep', "0.5");
}
$mindist = get_parameter('mindist', "1.0");
$kval = get_parameter('kval', "0.3");
$values = array();
$values['name'] = $name;
$values['id_group'] = $id_group;
@ -278,6 +288,11 @@ if ($new_networkmap || $save_networkmap) {
$filter['x_offs'] = $offset_x;
$filter['y_offs'] = $offset_y;
$filter['z_dash'] = $scale_z;
$filter['node_sep'] = $node_sep;
$filter['rank_sep'] = $rank_sep;
$filter['mindist'] = $mindist;
$filter['kval'] = $kval;
$values['filter'] = json_encode($filter);
$result = false;