summaryrefslogtreecommitdiff
path: root/scripts/model
diff options
context:
space:
mode:
authorAlon Levy <alon@pobox.com>2014-11-11 22:56:30 +0200
committerAlon Levy <alon@pobox.com>2014-11-11 22:56:30 +0200
commitc2e930bd9a19a6a10cc54985f51c9446a817e024 (patch)
tree7ced1ea1684af2ff6fdd50cc8b25591b6f110bd2 /scripts/model
parent68d8eddce3f4010dc88c6a0a9def701dd8f9b25b (diff)
graph: fix getConnectedNodesAndLinks
Diffstat (limited to 'scripts/model')
-rw-r--r--scripts/model/graph.js32
1 files changed, 18 insertions, 14 deletions
diff --git a/scripts/model/graph.js b/scripts/model/graph.js
index 33167552..389b0abe 100644
--- a/scripts/model/graph.js
+++ b/scripts/model/graph.js
@@ -125,7 +125,9 @@ function Graph(el) {
var i = 0,
j = 0,
adjacentnode,
- ret = {'nodes':[], 'links':{}};
+ link,
+ link2,
+ ret = {'nodes':[], 'links':[]};
$(".debug").html(n.state);
@@ -139,31 +141,33 @@ function Graph(el) {
d = d || 1;
while (i < links.length) {
- if (links[i].source === n) {
- adjacentnode = findNode(links[i].target.id, null);
+ link = links[i];
+ // XXX: using name comparison because n might be stale
+ if (compareNames(link.source.name, n.name)) {
+ adjacentnode = findNode(link.target.id, null);
if (adjacentnode.state !== "temp") {
- adjacentnode.state = "exit";
+ ret.nodes.push({type: 'exit', node: adjacentnode});
}
- links[i].state = "exit";
+ ret.links.push({type: 'exit', link: link});
- if (links[i].target.type === "chainlink") {
- console.log("chain");
+ if (link.target.type === "chainlink") {
while (j < links.length) {
- if (links[i].target.id === links[j].target.id &&
- links[j].target.type === "chainlink" &&
- links[j].target.state !== "temp") {
- adjacentnode = findNode(links[j].source.id, null);
+ link2 = links[j];
+ if (link.target.id === link2.target.id &&
+ link2.target.type === "chainlink" &&
+ link2.target.state !== "temp") {
+ adjacentnode = findNode(link2.source.id, null);
if (adjacentnode.state !== "temp") {
- adjacentnode.state = "enter";
+ ret.nodes.push({type: 'enter', node: adjacentnode});
}
- links[j].state = "enter";
+ ret.links.push({type: 'enter', link: link2});
}
j++;
}
}
j=0;
}
- if (links[i].target === n) {
+ if (compareNames(links[i].target.name, n.name)) {
adjacentnode = findNode(links[i].source.id, null);
if (adjacentnode.state !== "temp") adjacentnode.state = "enter";
links[i].state = "enter";