From 42ecb787cfd6a6adbfa87c0088666f1d700d5cbf Mon Sep 17 00:00:00 2001 From: mdtrooper Date: Mon, 21 Mar 2016 10:25:41 +0100 Subject: [PATCH] Some work. --- .../include/javascript/map/MapController.js | 88 ++++---- .../javascript/map/NetworkmapController.js | 207 ++++++++---------- 2 files changed, 133 insertions(+), 162 deletions(-) diff --git a/pandora_console/include/javascript/map/MapController.js b/pandora_console/include/javascript/map/MapController.js index bec47c14ef..6f89997bfa 100644 --- a/pandora_console/include/javascript/map/MapController.js +++ b/pandora_console/include/javascript/map/MapController.js @@ -214,6 +214,11 @@ MapController.prototype.minimap_get_size = function() { return minimap_size; } +/** +* Function get_node +* Return node +* This function returns a node +*/ MapController.prototype.get_node = function(id_graph) { var return_node = null; @@ -227,6 +232,11 @@ MapController.prototype.get_node = function(id_graph) { return return_node; } +/** +* Function get_node_type +* Return node type +* This function returns a node type (module, agent or edge) +*/ MapController.prototype.get_node_type = function(id_graph) { var self = this; @@ -239,6 +249,11 @@ MapController.prototype.get_node_type = function(id_graph) { return null; } +/** +* Function get_edges_from_node +* Return array[edge] +* This function returns the edges of a node +*/ MapController.prototype.get_edges_from_node = function(id_graph) { var edges = []; @@ -252,6 +267,27 @@ MapController.prototype.get_edges_from_node = function(id_graph) { return edges; } +MapController.prototype.get_arrow_from_id = function(id) { + var self = this; + + var arrow = $.grep(edges, function(e) { + if (e['graph_id'] == id) { + return true; + } + }); + + + if (arrow.length == 0) { + return null; + } + else { + arrow = arrow[0]; + + return self.get_arrow(arrow['to'], arrow['from']); + } + +} + /** * Function get_arrow * Return void @@ -260,30 +296,26 @@ MapController.prototype.get_edges_from_node = function(id_graph) { MapController.prototype.get_arrow = function(id_to, id_from) { var arrow = {}; - arrow['nodes'] = []; + arrow['nodes'] = {}; - var i = 0; + var count_nodes = 0; $.each(nodes, function(i, node) { - - if (node['graph_id'] == id_to) { - + if (parseInt(node['graph_id']) == parseInt(id_to)) { arrow['nodes']['to'] = node; - i++; + count_nodes++; } - else if (node['graph_id'] == id_from) { - + else if (parseInt(node['graph_id']) == parseInt(id_from)) { arrow['nodes']['from'] = node; - i++; + count_nodes++; } }); - if (i == 2) { - - $.each(arrows, function(i, arrow) { - if (arrow['to'] == arrow['nodes']['to'] && - arrow['from'] == arrow['nodes']['from']) { + if (count_nodes == 2) { + $.each(edges, function(i, edge) { + if (edge['to'] == arrow['nodes']['to']['graph_id'] && + edge['from'] == arrow['nodes']['from']['graph_id']) { - arrow['arrow'] = arrow; + arrow['arrow'] = edge; return false; // Break } @@ -465,9 +497,7 @@ MapController.prototype.paint_minimap = function() { var map_size = d3.select(self._target + " .viewport").node().getBBox(); var minimap_map_width = (map_size.width + map_size.x) / RELATION_MINIMAP; - //~ var minimap_map_width = (map_size.width) / RELATION_MINIMAP; var minimap_map_height = (map_size.height + map_size.y) / RELATION_MINIMAP; - //~ var minimap_map_height = (map_size.height) / RELATION_MINIMAP; var minimap = d3.select(self._target + " .minimap"); var svg = d3.select(self._target + " svg"); @@ -508,9 +538,6 @@ MapController.prototype.paint_minimap = function() { .attr("class", "map") .attr("transform", transform.toString()); - - - minimap_layer.append("rect") .attr("class", "viewport") .attr("style", "fill: #dddddd; stroke: #aaaaaa; stroke-width: 1;") @@ -1359,27 +1386,6 @@ MapController.prototype.init_events = function(principalObject) { self.remove_resize_square(); } - - //~ //For to catch the keyevent for the ctrl key - //~ d3.select(document) - //~ .on("keydown", function() { - //~ - //~ if (d3.event.keyCode == key_multiple_selection) { - //~ flag_multiple_selection = true; - //~ disabled_drag_zoom = true; - //~ } - //~ }) - //~ .on("keyup", function() { - //~ - //~ if (d3.event.keyCode == key_multiple_selection) { - //~ flag_multiple_selection = false; - //~ disabled_drag_zoom = false; - //~ flag_multiple_selection_running = false; - //~ - //~ d3.select("#selection_rectangle") - //~ .style("display", "none"); - //~ } - //~ }); } /** diff --git a/pandora_console/include/javascript/map/NetworkmapController.js b/pandora_console/include/javascript/map/NetworkmapController.js index dd05387b53..086b7d6558 100644 --- a/pandora_console/include/javascript/map/NetworkmapController.js +++ b/pandora_console/include/javascript/map/NetworkmapController.js @@ -92,61 +92,63 @@ NetworkmapController.prototype.is_arrow_module_to_module = function(id_to, id_fr * Return void * This function return if an arrow is module to agent arrow */ -NetworkmapController.prototype.is_arrow_AM = function(id_to, id_from) { - var self = this; - - var return_var = false; - - var arrow = self.get_arrow(id_to, id_from); - - if (arrow === null) { - return false; - } - - if (arrow['nodes'][0]['type'] == arrow['nodes'][1]['type']) { - return false; - } - - return true; -} +//~ NetworkmapController.prototype.is_arrow_AM = function(id_to, id_from) { + //~ var self = this; + //~ + //~ var return_var = false; + //~ + //~ var arrow = self.get_arrow(id_to, id_from); + //~ + //~ if (arrow === null) { + //~ return false; + //~ } + //~ + //~ if (arrow['nodes'][0]['type'] == arrow['nodes'][1]['type']) { + //~ return false; + //~ } + //~ + //~ return true; +//~ } /** * Function is_arrow_AMA (Agent -> Module -> Agent) * Return void * This function return if an arrow is agent to module to agent arrow */ -NetworkmapController.prototype.is_arrow_AMA = function(id_to, id_from) { - var self = this; - var var_return = false; - - if (self.is_arrow_AM(id_to, id_from)) { - var arrow = self.get_arrow(id_to, id_from); - - var module = null; - if (arrow['nodes'][0]['type'] == ITEM_TYPE_MODULE_NETWORKMAP) { - module = arrow['nodes'][0]; - } - else { - module = arrow['nodes'][1]; - } - - $.each(edges, function(i, edge) { - if ((edge['to'] == module['graph_id']) || - (edge['from'] == module['graph_id'])) { - - if (edge['graph_id'] != arrow['arrow']['graph_id']) { - - - var_return = true; - return false; //Break - } - } - }); - } - - return var_return; -} +//~ NetworkmapController.prototype.is_arrow_AMA = function(id_to, id_from) { + //~ var self = this; + //~ var var_return = false; + //~ + //~ if (self.is_arrow_AM(id_to, id_from)) { + //~ var arrow = self.get_arrow(id_to, id_from); + //~ + //~ var module = null; + //~ if (arrow['nodes'][0]['type'] == ITEM_TYPE_MODULE_NETWORKMAP) { + //~ module = arrow['nodes'][0]; + //~ } + //~ else { + //~ module = arrow['nodes'][1]; + //~ } + //~ + //~ $.each(edges, function(i, edge) { + //~ if ((edge['to'] == module['graph_id']) || + //~ (edge['from'] == module['graph_id'])) { + //~ if (edge['graph_id'] != arrow['arrow']['graph_id']) { + //~ var_return = true; + //~ return false; //Break + //~ } + //~ } + //~ }); + //~ } + //~ + //~ return var_return; +//~ } +/** +* Function get_arrow_AMMA +* Return array (arrow) +* This function returns an AMMA arrow +*/ NetworkmapController.prototype.get_arrow_AMMA = function(id_to, id_from) { var self = this; @@ -185,7 +187,6 @@ NetworkmapController.prototype.get_arrow_AMMA = function(id_to, id_from) { if (arrow_to !== null && arrow_from !== null) { // There is one arrow for A-M-M-A - arrow_to = self.get_arrow(arrow_to['id_to'], arrow_to['id_from']); arrow_from = self.get_arrow(arrow_from['id_to'], arrow_from['id_from']); @@ -218,7 +219,11 @@ NetworkmapController.prototype.get_arrow_AMMA = function(id_to, id_from) { return return_var; } - +/** +* Function get_arrow_AMA +* Return array (arrow) +* This function returns an AMA arrow +*/ NetworkmapController.prototype.get_arrows_AMA = function(id_to, id_from) { var self = this; @@ -268,57 +273,17 @@ NetworkmapController.prototype.get_arrows_AMA = function(id_to, id_from) { } }); } - - // TRASH - //~ - //~ if (edges_from != null) { - //~ $.each(edges_from, function(i, edge) { - //~ - //~ if ((edge['to'] != id_to) && (edge['from'] != id_from)) { - //~ - //~ } - //~ - //~ - //~ if (arrow['nodes']['from']['id_graph'] == id_from) { - //~ if (arrow['nodes']['to']['type'] == ITEM_TYPE_AGENT_NETWORKMAP) { - //~ var temp = {}; - //~ - //~ temp['graph_id'] = - //~ arrow['arrow']['graph_id'] + "" + - //~ arrow_AM['arrow']['graph_id'] + ""; - //~ - //~ temp['AMMA'] = 0; - //~ temp['AMA'] = 1; - //~ - //~ - //~ temp['to'] = id_to; - //~ if (arrow['nodes']['from']['type'] == ITEM_TYPE_AGENT_NETWORKMAP) { - //~ temp['from'] = arrow['nodes']['from']['id_graph']; - //~ } - //~ else { - //~ temp['from'] = arrow['nodes']['to']['id_graph']; - //~ } - //~ - //~ - //~ temp['to_module'] = arrow_AM['nodes']['from']['id']; - //~ temp['from_module'] = null; - //~ - //~ arrows.push(temp); - //~ } - //~ } - //~ }); - //~ } - //~ else if (edges_to != null) { - //~ $.each(arrows_to, function(i, arrow) { - //~ - //~ }); - //~ } } }); return var_return; } +/** +* Function exists_arrow +* Return bool +* This function returns if the arrow exists +*/ NetworkmapController.prototype.exists_arrow = function(arrows, arrow) { var var_return = false; @@ -357,30 +322,30 @@ NetworkmapController.prototype.paint_arrows = function() { }); //TO DO - var arrow_layouts = self._viewport.selectAll(".arrow") - .data( - edges - .filter(function(d, i) { - if (self.is_arrow_module_to_module(d['to'], d['from'])) { - return true; - } - else if (self.is_arrow_AMA(d['to'], d['from'])) { - if (self.is_arrow_in_map(d['to'], d['from'])) - return false; - else - return true; - } - - return false; - })) - .enter() - .append("g") - .attr("class", "arrow") - .attr("id", function(d) { return "arrow_" + d['graph_id'];}) - - .attr("data-id", function(d) { return d['id'];}) - .attr("data-to", function(d) { - return self.node_from_edge(d['graph_id'])["to"];}) - .attr("data-from", function(d) { - return self.node_from_edge(d['graph_id'])["from"];}); + //~ var arrow_layouts = self._viewport.selectAll(".arrow") + //~ .data( + //~ edges + //~ .filter(function(d, i) { + //~ if (self.is_arrow_module_to_module(d['to'], d['from'])) { + //~ return true; + //~ } + //~ else if (self.is_arrow_AMA(d['to'], d['from'])) { + //~ if (self.is_arrow_in_map(d['to'], d['from'])) + //~ return false; + //~ else + //~ return true; + //~ } + //~ + //~ return false; + //~ })) + //~ .enter() + //~ .append("g") + //~ .attr("class", "arrow") + //~ .attr("id", function(d) { return "arrow_" + d['graph_id'];}) + //~ + //~ .attr("data-id", function(d) { return d['id'];}) + //~ .attr("data-to", function(d) { + //~ return self.node_from_edge(d['graph_id'])["to"];}) + //~ .attr("data-from", function(d) { + //~ return self.node_from_edge(d['graph_id'])["from"];}); }