From fc7ecac8c22e79f669b2e4ff28f32641102ebfd3 Mon Sep 17 00:00:00 2001 From: Alon Levy Date: Tue, 7 Oct 2014 08:50:56 +0300 Subject: 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) --- scripts/textanalysis.js | 40 +++++++++++++++++++++++++++++----------- 1 file changed, 29 insertions(+), 11 deletions(-) (limited to 'scripts/textanalysis.js') 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; -- cgit v1.3.1