summaryrefslogtreecommitdiff
path: root/src/client/model/graph.js
diff options
context:
space:
mode:
authorAlon Levy <alon@pobox.com>2015-05-13 23:45:04 +0300
committerAlon Levy <alon@pobox.com>2015-05-18 18:19:48 +0300
commit3f856ddb4350d83f252c988bfe810814192ff7b4 (patch)
tree893a27ada06918305919d75604e798e6b2454cfe /src/client/model/graph.js
parentfd6f9c830d04626b914dc9fd2766bfedd68be8c3 (diff)
client/model/graph: refactor kind out of neighbourhood
Diffstat (limited to 'src/client/model/graph.js')
-rw-r--r--src/client/model/graph.js41
1 files changed, 23 insertions, 18 deletions
diff --git a/src/client/model/graph.js b/src/client/model/graph.js
index 658d33d6..ef40983e 100644
--- a/src/client/model/graph.js
+++ b/src/client/model/graph.js
@@ -250,6 +250,25 @@ function Graph(spec) {
));
}
+
+ /**
+ * Visitation constants for neighbourhood and shortest paths computation.
+ */
+ var kind_exit = 1,
+ kind_enter = 2,
+ kind_selected = 4;
+
+ function kind_to_string(kind) {
+ switch (kind) {
+ case kind_exit: return 'exit';
+ case kind_enter: return 'enter';
+ case kind_selected: return 'selected';
+ default:
+ // TODO: add css for both
+ return 'exit';
+ }
+ }
+
/**
*
* neighbourhood
@@ -313,11 +332,8 @@ function Graph(spec) {
var nodes = get_nodes(),
links = get_links(),
neighbours = calc_neighbours(),
- exit = 1,
- enter = 2,
- selected = 4,
visited = _.object(_.map(start, get_name),
- _.map(start, _.partial(make_status, selected)));
+ _.map(start, _.partial(make_status, kind_selected)));
function visit(source, link, getter, kind, depth) {
var node = getter(link),
@@ -334,25 +350,14 @@ function Graph(spec) {
return data;
}
- function kind_to_string(kind) {
- switch (kind) {
- case exit: return 'exit';
- case enter: return 'enter';
- case selected: return 'selected';
- default:
- // TODO: add css for both
- return 'exit';
- }
- }
-
_.each(start, function (node) {
var N = neighbours[node.id];
_.each(N.src, function (link) {
- visit(node, link, function (link) { return link.__dst; }, enter);
+ visit(node, link, function (link) { return link.__dst; }, kind_enter);
});
_.each(N.dst, function (link) {
- visit(node, link, function (link) { return link.__src; }, exit);
+ visit(node, link, function (link) { return link.__src; }, kind_exit);
});
});
_.values(visited).forEach(function (data) {
@@ -360,7 +365,7 @@ function Graph(spec) {
kind = data.kind,
links = data.links;
- if ((kind & selected) === selected) {
+ if ((kind & kind_selected) === kind_selected) {
return;
}
ret.nodes.push({type: kind_to_string(kind), node: node, sources: data.sources});