diff options
Diffstat (limited to 'scripts')
| -rw-r--r-- | scripts/model/graph.js | 103 | ||||
| -rw-r--r-- | scripts/rhizicore.js | 52 |
2 files changed, 105 insertions, 50 deletions
diff --git a/scripts/model/graph.js b/scripts/model/graph.js index 657640bb..5f2d51eb 100644 --- a/scripts/model/graph.js +++ b/scripts/model/graph.js @@ -96,62 +96,77 @@ function Graph(el) { } } - - this.highlightNode = function(id, state) { + /** + * + * getConnectedNodesAndLinks + * + * @id + * @state - defines the starting node (must have id and state) + * @d - depth defining connected component. If -1 returns the entire connected component. (can be the whole graph) + * + * NOTE: chainlinks are treated specially, they don't count for distance. So all their decendants will be added. + * + * NOTE: temp state nodes (n.state === 'temp') are ignored. + * + * @return - { + * 'node': [node] + * 'link': [link] + * } + * + * TODO: rewrite using efficient data structure. Right now iterates over everything + * TODO: implement for d !== 1 + * + */ + this.getConnectedNodesAndLinks = function(n, d) { var i = 0, - j = 0; - var n = findNode(id, state); - var adjacentnode; + j = 0, + adjacentnode, + ret = {'nodes':[], 'links':{}}; + $(".debug").html(n.state); - //highlight node - if (n !== undefined && n.state !== "chosen" && n.state !== "temp") { - this.removeHighlight(); - n.state = "chosen"; + if (n === undefined) { + console.log('getConnectedNodesAndLinks: bug: called with undefined node'); + return; + } + if (d !== 1) { + console.log('getConnectedNodesAndLinks: bug: not implemented for d == ' + d); + } + d = d || 1; - while (i < links.length) { - if (links[i]['source'] === n) { - adjacentnode = findNode(links[i]['target'].id, null); - if (adjacentnode.state !== "temp") adjacentnode.state = "exit"; - links[i]['state'] = "exit"; + while (i < links.length) { + if (links[i].source === n) { + adjacentnode = findNode(links[i].target.id, null); + if (adjacentnode.state !== "temp") { + adjacentnode.state = "exit"; + } + links[i].state = "exit"; - if(links[i]['target'].type==="chainlink"){ - console.log("chain"); - 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); - if (adjacentnode.state !== "temp") adjacentnode.state = "enter"; - links[j]['state'] = "enter"; + if (links[i].target.type === "chainlink") { + console.log("chain"); + 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); + if (adjacentnode.state !== "temp") { + adjacentnode.state = "enter"; } - j++; + links[j].state = "enter"; } + j++; } - j=0; - } - if (links[i]['target'] === n) { - adjacentnode = findNode(links[i]['source'].id, null); - if (adjacentnode.state !== "temp") adjacentnode.state = "enter"; - links[i]['state'] = "enter"; } - i++; + j=0; } - } - } - - this.removeHighlight = function() { - var k = 0; - while (k < nodes.length) { - if (nodes[k]['state'] === "enter" || nodes[k]['state'] === "exit" || nodes[k]['state'] === "chosen") { - nodes[k]['state'] = "perm"; + if (links[i].target === n) { + adjacentnode = findNode(links[i].source.id, null); + if (adjacentnode.state !== "temp") adjacentnode.state = "enter"; + links[i].state = "enter"; } - k++; - } - var j = 0; - //highlight all connections - while (j < links.length) { - links[j]['state'] = "perm"; - j++; + i++; } + return ret; } /* compareSubset: diff --git a/scripts/rhizicore.js b/scripts/rhizicore.js index bf4dd46e..2e20edda 100644 --- a/scripts/rhizicore.js +++ b/scripts/rhizicore.js @@ -267,9 +267,9 @@ function update(no_relayout) { } d3.event.stopPropagation(); if(d.state!=="temp") { - showInfo(d, i); + showInfo(d, i); } else { - graph.removeHighlight(); + removeHighlight(); } update(true); }); @@ -475,9 +475,49 @@ function tick(e) { node.attr('visibility', 'visible'); } +function removeHighlight() { + // TODO: stop manipulating state + var nodes = graph.nodes(), + links = graph.links(), + k = 0, j = 0; + + while (k < nodes.length) { + if (nodes[k]['state'] === "enter" || nodes[k]['state'] === "exit" || nodes[k]['state'] === "chosen") { + nodes[k]['state'] = "perm"; + } + k++; + } + while (j < links.length) { + links[j]['state'] = "perm"; + j++; + } +} + +function highlight(n) +{ + var connected = graph.getConnectedNodesAndLinks(n, 1), + i, + data; + + n.state = 'chosen'; + + for (i in connected.nodes) { + data = connected.nodes[i]; + node = data.node; + switch (data.type) { + case 'exit': + node.state = 'exit'; + break; + case 'enter': + node.state = 'enter'; + break; + }; + } +} + function showInfo(d, i) { - if (d.state !== "chosen") { - graph.highlightNode(d.id, null); + if (d.state !== "chosen" && d.state !== 'temp') { + highlight(d); $('.info').fadeIn(300); if (d.type === "deliverable") { @@ -532,7 +572,7 @@ function showInfo(d, i) { } }); } else { - graph.removeHighlight(); + removeHighlight(); $('.info').fadeOut(300); } graph.update(true); @@ -543,7 +583,7 @@ function mousedown() { $('.editinfo').css('left', 0); $('.editlinkinfo').css('top', -100); $('.editlinkinfo').css('left', 0); - graph.removeHighlight(); + removeHighlight(); $('.info').fadeOut(300); graph.update(true); } |
