From dd2c16e22b76ca299c4edfcd8f62d22e6bf39baa Mon Sep 17 00:00:00 2001 From: Alon Levy Date: Mon, 9 Mar 2015 20:09:48 +0200 Subject: client: search in nodes and attributes Fixes #358 Implementation limitations: - uses hasOwnProperty for search, and further filters on strings. So technically could be oversearching - i.e. string properties that are not attributes. We should keep an attribute key on Node and Link - there is no selected link, just selected nodes. So we select both source and destination. Opening issue #367 for this. --- src/client/view/selection.js | 23 +++++++++++++++++++++-- 1 file changed, 21 insertions(+), 2 deletions(-) (limited to 'src/client/view/selection.js') diff --git a/src/client/view/selection.js b/src/client/view/selection.js index 6ac675aa..7a99dd03 100644 --- a/src/client/view/selection.js +++ b/src/client/view/selection.js @@ -117,10 +117,29 @@ function updateSelectedNodesBus(new_selected_nodes) selectionChangedBus.push(new_selection(selected_nodes, root_nodes)); } +/* add nodes in nodes_b to a copy of nodes_a in order, skipping duplicates */ +function sum_nodes(nodes_a, nodes_b) +{ + var set_a_id = _.object(nodes_a.map(function (n) { return [n.id, 1]; })), + ret = nodes_a.slice(0); + + for (var k in nodes_b) { + if (set_a_id[nodes_b[k].id] === undefined) { + ret.push(nodes_b[k]); + } + } + return ret; +} + +function links_to_nodes(links) +{ + return _.flatten(_.map(links, function (link) { return [link.__src, link.__dst]; })); +} + function byVisitors(node_selector, link_selector) { - var new_selected_nodes = get_main_graph().find__by_visitors(node_selector, link_selector); + var new_selection = get_main_graph().find__by_visitors(node_selector, link_selector); - inner_update(new_selected_nodes); + inner_update(sum_nodes(new_selection.nodes, links_to_nodes(new_selection.links))); } function connectedComponent(nodes) { -- cgit v1.3.1