Topo2: Update multilink positions when scaling
JIRA Tasks; ONOS-6340

Change-Id: I0be48bddd179984179a90107bfe5b7bf062e2ab9
diff --git a/web/gui/src/main/webapp/app/view/topo2/topo2Link.js b/web/gui/src/main/webapp/app/view/topo2/topo2Link.js
index 37affce..77892ab 100644
--- a/web/gui/src/main/webapp/app/view/topo2/topo2Link.js
+++ b/web/gui/src/main/webapp/app/view/topo2/topo2Link.js
@@ -212,7 +212,8 @@
                 this.setScale();
             },
             amt: function (numLinks, index) {
-                var gap = 6;
+                var bbox = this.get('source').el.node().getBBox(),
+                    gap = bbox.width / 4;
                 return (index - ((numLinks - 1) / 2)) * gap;
             },
             defaultPosition: function () {
@@ -250,6 +251,11 @@
                 if (this.get('enhanced')) {
                     this.updatePortPosition();
                 }
+
+                if (this.el) {
+                    this.el.attr(this.get('position'));
+                }
+
             },
             updatePortPosition: function () {
                 var sourcePos = this.locatePortLabel(1),
@@ -334,6 +340,8 @@
                     .selectAll('*')
                     .style('transform', 'scale(' + labelScale + ')');
 
+                this.setPosition();
+
             },
             update: function () {
                 if (this.get('enhanced')) {
diff --git a/web/gui/src/main/webapp/app/view/topo2/topo2Region.js b/web/gui/src/main/webapp/app/view/topo2/topo2Region.js
index 643aaa5..8fbe814 100644
--- a/web/gui/src/main/webapp/app/view/topo2/topo2Region.js
+++ b/web/gui/src/main/webapp/app/view/topo2/topo2Region.js
@@ -112,33 +112,34 @@
                         deviceConnections = {};
 
                     _.each(this.regionData.links, function (link) {
-                        var devA = _this.removePort(link.epA),
-                            devB = _this.removePort(link.epB),
-                            key = devA + '~' + devB;
 
-                        if (!deviceConnections[key]) {
-                            deviceConnections[key] = [];
-                        }
+                        var epA = _this.removePort(link.epA),
+                            epB = _this.removePort(link.epB),
+                            key = epA + '~' + epB,
+                            collection = deviceConnections[key] || [],
+                            dup = _.find(collection, link);
 
                         // TODO: Investigate why region contains dup links?!?!
                         // FIXME: This shouldn't be needed - The backend is sending dups
                         //        and this is preventing the client thinking its a multilink
-                        if (deviceConnections[key].indexOf(link) > -1) {
-                            deviceConnections[key].push(link);
+                        if (!dup) {
+                            collection.push(link);
                         }
+
+                        deviceConnections[key] = collection;
                     });
 
-                    _.each(deviceConnections, function (connection) {
-                        if (connection.length > 1) {
-                            _.orderBy(connection, ['portA']);
-                            _.each(connection, function (link, index) {
+                    _.forIn(deviceConnections, function (collection) {
+                        if (collection.length > 1) {
+                            _.each(collection, function (link, index) {
                                 link.multiline = {
-                                    deviceLinks: connection.length,
+                                    deviceLinks: collection.length,
                                     index: index
-                                };
-                            })
+                                }
+                            });
                         }
-                    });
+                    })
+
                 },
                 isRootRegion: function () {
                     return this.model.get('id') === ROOT;