diff options
| author | Alon Levy <alon@pobox.com> | 2015-03-09 20:09:48 +0200 |
|---|---|---|
| committer | Alon Levy <alon@pobox.com> | 2015-03-09 20:12:31 +0200 |
| commit | dd2c16e22b76ca299c4edfcd8f62d22e6bf39baa (patch) | |
| tree | 072390f028ac6bf80ff3caec7f27188aa8dd1d5c /src/client/view/selection.js | |
| parent | 05e7b8021d17772f3fb0db4667b7901b1c34a474 (diff) | |
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.
Diffstat (limited to 'src/client/view/selection.js')
| -rw-r--r-- | src/client/view/selection.js | 23 |
1 files changed, 21 insertions, 2 deletions
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) { |
