Topo2: Improved the force layout implementation
topo2Collection: Models can be added to a collection aswell as js objects
topo2Layout: New nodes/links are added to the force layout and
the simulation starts again (this was causing a bug
where new nodes wouldn't have drag functionality)
Change-Id: I800b76e09989a07277184f5d14cbfa00ee675967
diff --git a/web/gui/src/main/webapp/app/view/topo2/topo2Collection.js b/web/gui/src/main/webapp/app/view/topo2/topo2Collection.js
index 5472f65..ae96acb 100644
--- a/web/gui/src/main/webapp/app/view/topo2/topo2Collection.js
+++ b/web/gui/src/main/webapp/app/view/topo2/topo2Collection.js
@@ -43,6 +43,12 @@
Collection.prototype = {
model: Model,
addModel: function (data) {
+ if (Object.getPrototypeOf(data) !== Object.prototype) {
+ this.models.push(data);
+ this._byId[data.get('id')] = data;
+ return data;
+ }
+
var CollectionModel = this.model;
var model = new CollectionModel(data, this);
diff --git a/web/gui/src/main/webapp/app/view/topo2/topo2Layout.js b/web/gui/src/main/webapp/app/view/topo2/topo2Layout.js
index 473bd3a..156d67a 100644
--- a/web/gui/src/main/webapp/app/view/topo2/topo2Layout.js
+++ b/web/gui/src/main/webapp/app/view/topo2/topo2Layout.js
@@ -208,6 +208,7 @@
_update: function () {
this.updateNodes();
this.updateLinks();
+ this.force.start();
},
updateNodes: function () {
var regionNodes = t2rs.regionNodes();
@@ -235,6 +236,8 @@
entering.filter('.sub-region').each(t2d3.nodeEnter);
entering.filter('.host').each(t2d3.nodeEnter);
entering.filter('.peer-region').each(t2d3.nodeEnter);
+
+ this.force.nodes(regionNodes);
},
updateLinks: function () {
@@ -269,6 +272,8 @@
})
.style('opacity', 0.0)
.remove();
+
+ this.force.links(regionLinks);
},
calcPosition: function () {
var lines = this;