summaryrefslogtreecommitdiff
path: root/scripts/model
diff options
context:
space:
mode:
authorAlon Levy <alon@pobox.com>2014-11-03 15:15:02 +0200
committerAlon Levy <alon@pobox.com>2014-11-03 15:19:30 +0200
commit02482e9f9ffe9467489b78a6fce8a9223bc8c2ad (patch)
treebb62b9477ae99614219b5e0e485535551d2a5420 /scripts/model
parent3d47fdfa2ff4b627084206fd83441d8a3873d075 (diff)
fix _addNodeNoHistory to correctly look for existing nodes
Diffstat (limited to 'scripts/model')
-rw-r--r--scripts/model/graph.js20
1 files changed, 12 insertions, 8 deletions
diff --git a/scripts/model/graph.js b/scripts/model/graph.js
index ad4678d0..c8a0e64c 100644
--- a/scripts/model/graph.js
+++ b/scripts/model/graph.js
@@ -36,13 +36,17 @@ function Graph(el) {
this._addNodeNoHistory = function(spec) {
// No history recorded - this is a helper for loading from files / constant graphs
- var id = spec.id || id_generator();
- var node = findNode(id, null);
- var new_node = undefined;
-
+ var node;
+ if (spec.id === undefined) {
+ node = findNodeByName(spec.name, null);
+ } else {
+ if (spec.id !== undefined) {
+ node = findNode(spec.id, null);
+ }
+ }
if (node === undefined) {
- new_node = {
- "id": id,
+ node = {
+ "id": spec.id || id_generator(),
"name": spec.name,
"type": spec.type,
"state": spec.state,
@@ -53,9 +57,9 @@ function Graph(el) {
'x': spec.x,
'y': spec.y,
};
- nodes.push(new_node);
+ nodes.push(node);
}
- return new_node;
+ return node;
}
this.removeNode = function(id, state) {