diff options
| author | Alon Levy <alon@pobox.com> | 2014-11-24 20:30:09 +0200 |
|---|---|---|
| committer | Alon Levy <alon@pobox.com> | 2014-11-24 20:30:09 +0200 |
| commit | f2ce89be26456be0fba9b298a19e98b83482170d (patch) | |
| tree | d4cc432d2f8023859bfa91278484b250fa8eaf50 /src/model | |
| parent | 224b9b40ef7ac3b560c28eaef8dea0473d362e71 (diff) | |
add search
The added input lets you select by *oring* multiple space less
expressions. i.e. 'a b' will find all nodes with name containing either
'a' or 'b'. Not the specification, will be remedied later (i.e. maybe
tomorrow, who knows).
excuse the bulk commit, this does 3 things:
splits off selection logic into src/view/selection
- handles setting state explicityl on Node's, still bad.
- bad at least the 'selected' state (i.e. boolean) is in one place.
- common point for clicking on nodes/edges and selecting view selection
input
makes graph.getConnectedNodesAndLinks accept an array and not just a
single node
implements the search functionality outlined in the first paragraph.
Diffstat (limited to 'src/model')
| -rw-r--r-- | src/model/graph.js | 106 |
1 files changed, 77 insertions, 29 deletions
diff --git a/src/model/graph.js b/src/model/graph.js index 6d13a83e..a71ba4c5 100644 --- a/src/model/graph.js +++ b/src/model/graph.js @@ -118,7 +118,7 @@ function Graph() { * TODO: implement for d !== 1 * */ - this.getConnectedNodesAndLinks = function(n, d) { + this.getConnectedNodesAndLinks = function(chosen_nodes, d) { var i = 0, j = 0, adjacentnode, @@ -126,9 +126,7 @@ function Graph() { link2, ret = {'nodes':[], 'links':[]}; - $(".debug").html(n.state); - - if (n === undefined) { + if (chosen_nodes === undefined) { console.log('getConnectedNodesAndLinks: bug: called with undefined node'); return; } @@ -137,38 +135,44 @@ function Graph() { } d = d || 1; + if (chosen_nodes.length === undefined) { + console.log('getConnectedNodesAndLinks: expected array'); + } + while (i < links.length) { link = links[i]; - // XXX: using name comparison because n might be stale - if (compareNames(link.__src.name, n.name)) { - adjacentnode = findNode(link.__dst.id, null); - if (adjacentnode.state !== "temp") { - ret.nodes.push({type: 'exit', node: adjacentnode}); - } - ret.links.push({type: 'exit', link: link}); + chosen_nodes.forEach(function (n) { + // XXX: using name comparison because n might be stale + if (compareNames(link.__src.name, n.name)) { + adjacentnode = findNode(link.__dst.id, null); + if (adjacentnode.state !== "temp") { + ret.nodes.push({type: 'exit', node: adjacentnode}); + } + ret.links.push({type: 'exit', link: link}); - if (link.__dst.type === "chainlink") { - while (j < links.length) { - link2 = links[j]; - if (link.__dst.id === link2.__dst.id && - link2.__dst.type === "chainlink" && - link2.__dst.state !== "temp") { - adjacentnode = findNode(link2.__src.id, null); - if (adjacentnode.state !== "temp") { - ret.nodes.push({type: 'enter', node: adjacentnode}); + if (link.__dst.type === "chainlink") { + while (j < links.length) { + link2 = links[j]; + if (link.__dst.id === link2.__dst.id && + link2.__dst.type === "chainlink" && + link2.__dst.state !== "temp") { + adjacentnode = findNode(link2.__src.id, null); + if (adjacentnode.state !== "temp") { + ret.nodes.push({type: 'enter', node: adjacentnode}); + } + ret.links.push({type: 'enter', link: link2}); } - ret.links.push({type: 'enter', link: link2}); + j++; } - j++; } + j=0; } - j=0; - } - if (compareNames(links[i].__dst.name, n.name)) { - adjacentnode = findNode(links[i].__src.id, null); - if (adjacentnode.state !== "temp") adjacentnode.state = "enter"; - links[i].state = "enter"; - } + if (compareNames(links[i].__dst.name, n.name)) { + adjacentnode = findNode(links[i].__src.id, null); + if (adjacentnode.state !== "temp") adjacentnode.state = "enter"; + links[i].state = "enter"; + } + }); i++; } return ret; @@ -634,6 +638,50 @@ function Graph() { var get_links = function() { return links; }; this.links = get_links; + function setRegularState() { + var x, node, link, s; + + for (x in nodes) { + node = nodes[x]; + s = node.state; + if (s === 'chosen' || s === 'enter' || s === 'exit') { + node.state = 'perm'; + } + } + for (x in links) { + link = links[x]; + s = link.state; + if (s === 'chosen' || s === 'enter' || s === 'exit') { + link.state = 'perm'; + } + } + } + this.setRegularState = setRegularState; + + this.findByVisitors = function(node_visitor, link_visitor) { + var n_length = nodes.length, + l_length = links.length, + selected = [], + i, + node, + link, + state; + + if (!node_visitor) { + return; + } + + for (i = 0 ; i < n_length; ++i) { + node = nodes[i]; + if (node.state == 'temp') { + continue; + } + if (node_visitor(node)) { + selected.push(node); + } + } + return selected; + } } return { |
