summaryrefslogtreecommitdiff
path: root/scripts/textanalysis.js
diff options
context:
space:
mode:
authorAlon Levy <alon@pobox.com>2014-10-07 08:50:56 +0300
committerAlon Levy <alon@pobox.com>2014-10-07 08:51:43 +0300
commitfc7ecac8c22e79f669b2e4ff28f32641102ebfd3 (patch)
tree2dbb028eea72e5a7e50b56b59f41808f8c02bed4 /scripts/textanalysis.js
parent7a0e1027dd7d8c0cbf60f406a64b24c0a9f284b8 (diff)
rhizicore: don't move graph when only changing link or node text
Fixes #49 Note about solution: in general we need to find out whether the graph from the new text (NewVertices, NewLinks) is homologous to the graph from the old text (OldVertices, OldLinks). The implemented solution only checks an easier case, where there is a single renamed vertex. A better solution to do later: - have textanalysis have state - have textanalysis return the difference from the last state: nodes added nodes deleted nodes changed - plus for bonus refactor all the editing functions (edit* in myGraph)
Diffstat (limited to 'scripts/textanalysis.js')
-rw-r--r--scripts/textanalysis.js40
1 files changed, 29 insertions, 11 deletions
diff --git a/scripts/textanalysis.js b/scripts/textanalysis.js
index a93839aa..74b029ae 100644
--- a/scripts/textanalysis.js
+++ b/scripts/textanalysis.js
@@ -314,19 +314,37 @@ var textAnalyser2 = function (newtext, finalize) {
lastnode = newnodes[nodeindex];
ret.applyToGraph = function(graph) {
- //REINITIALISE GRAPH (DUMB BUT IT WORKS)
- graph.removeNodes("temp");
- graph.removeLinks("temp");
- for (var k in ret.nodes) {
- var n = ret.nodes[k];
- graph.addNode(n.id, n.type, n.state);
- }
- for (var k in ret.links) {
- var l = ret.links[k];
- graph.addLink(l.sourceId, l.targetId, l.name, l.state, ret.drop_conjugator_links);
+ window.ret = ret;
+ var comp = graph.compareSubset('temp', ret.nodes.filter(
+ function(node) {
+ return !graph.hasNode(node.id, "perm");
+ }).map(function (node) {
+ return node.id;
+ }), ret.links.map(
+ function (link) {
+ return [link.sourceId.toLowerCase(), link.targetId.toLowerCase()];
+ }
+ ));
+ var k, n;
+ if (comp.graph_same && !finalize) {
+ if (comp.old_id && comp.new_id) {
+ graph.editName(comp.old_id, null, comp.new_id);
+ }
+ } else {
+ //REINITIALISE GRAPH (DUMB BUT IT WORKS)
+ graph.removeNodes("temp");
+ graph.removeLinks("temp");
+ for (k in ret.nodes) {
+ n = ret.nodes[k];
+ graph.addNode(n.id, n.type, n.state);
+ }
+ for (k in ret.links) {
+ var l = ret.links[k];
+ graph.addLink(l.sourceId, l.targetId, l.name, l.state, ret.drop_conjugator_links);
+ }
}
//UPDATE GRAPH ONCE
- graph.update();
+ graph.update(!finalize && comp.graph_same);
}
return ret;