summaryrefslogtreecommitdiff
path: root/src/client/model/graph.js
diff options
context:
space:
mode:
authorAlon Levy <alon@pobox.com>2015-03-09 20:09:48 +0200
committerAlon Levy <alon@pobox.com>2015-03-09 20:12:31 +0200
commitdd2c16e22b76ca299c4edfcd8f62d22e6bf39baa (patch)
tree072390f028ac6bf80ff3caec7f27188aa8dd1d5c /src/client/model/graph.js
parent05e7b8021d17772f3fb0db4667b7901b1c34a474 (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/model/graph.js')
-rw-r--r--src/client/model/graph.js21
1 files changed, 6 insertions, 15 deletions
diff --git a/src/client/model/graph.js b/src/client/model/graph.js
index 2fd453e7..f38686eb 100644
--- a/src/client/model/graph.js
+++ b/src/client/model/graph.js
@@ -1091,25 +1091,16 @@ function Graph(spec) {
this.find__by_visitors = function(node_visitor, link_visitor) {
var nodes = get_nodes(),
links = get_links(),
- n_length = nodes.length,
- l_length = links.length,
- selected = [],
- i,
- node,
- link,
- state;
+ selected_nodes,
+ selected_links;
- if (!node_visitor) {
+ if (!node_visitor && !link_visitor) {
return;
}
- for (i = 0 ; i < n_length; ++i) {
- node = nodes[i];
- if (node_visitor(node)) {
- selected.push(node);
- }
- }
- return selected;
+ selected_nodes = node_visitor ? nodes.filter(node_visitor) : [];
+ selected_links = link_visitor ? links.filter(link_visitor) : [];
+ return {nodes: selected_nodes, links: selected_links};
}
function markRelated(names) {