Topo2: Bug fixes
1: port lables not showing on mouseover
2: D3 Errors when there are no topology errors and a user pans/zooms

Change-Id: Ic65ba393d23b60673c3a731d1986ee15bbe1bd88
diff --git a/web/gui/src/main/webapp/app/view/topo2/topo2Force.js b/web/gui/src/main/webapp/app/view/topo2/topo2Force.js
index 1c2ea67..0e93868 100644
--- a/web/gui/src/main/webapp/app/view/topo2/topo2Force.js
+++ b/web/gui/src/main/webapp/app/view/topo2/topo2Force.js
@@ -34,16 +34,18 @@
 
     // ========================== Helper Functions
 
-    function init(_svg_, _forceG_, _uplink_, _dim_, zoomer, _opts_) {
+    function init(_svg_, _forceG_, _uplink_, _dim_, _zoomer_, _opts_) {
+
         svg = _svg_;
-        forceG = _forceG_;
         uplink = _uplink_;
         dim = _dim_;
+        zoomer = _zoomer_;
         opts = _opts_;
 
-        t2bcs.addLayout(t2ls);
+
         t2bgs.init();
-        t2ls = t2ls(svg, forceG, uplink, dim, zoomer, opts);
+        t2ls.init(svg, uplink, dim, zoomer, opts);
+        t2bcs.addLayout(t2ls);
         t2rs.layout = t2ls;
         t2ss.init(svg, zoomer);
     }
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 75105ba..c3bfd58 100644
--- a/web/gui/src/main/webapp/app/view/topo2/topo2Layout.js
+++ b/web/gui/src/main/webapp/app/view/topo2/topo2Layout.js
@@ -97,7 +97,7 @@
                       ViewController) {
 
                 var Layout = ViewController.extend({
-                    initialize: function (svg, forceG, uplink, dim, zoomer, opts) {
+                    init: function (svg, forceG, uplink, dim, zoomer, opts) {
                         $log.debug('initialize Layout');
                         instance = this;
 
@@ -371,7 +371,7 @@
                     return instance || new Layout(svg, forceG, uplink, dim, zoomer, opts);
                 }
 
-                return getInstance;
+                return getInstance();
             }
         ]
     );
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 be8d03c..e644c7c 100644
--- a/web/gui/src/main/webapp/app/view/topo2/topo2Link.js
+++ b/web/gui/src/main/webapp/app/view/topo2/topo2Link.js
@@ -174,7 +174,7 @@
                         data.push(point);
                     }
 
-                    var entering = d3.select('#topo2-portLabels')
+                    var entering = d3.select('.topo2-portLabels')
                         .selectAll('.portLabel')
                         .data(data)
                         .enter().append('g')
@@ -204,7 +204,7 @@
             },
             unenhance: function () {
                 this.set('enhanced', false);
-                d3.select('#topo2-portLabels').selectAll('.portLabel').remove();
+                d3.select('.topo2-portLabels').selectAll('.portLabel').remove();
             },
             getSelected: function () {
                 return this.collection.filter(function (m) {
diff --git a/web/gui/src/main/webapp/app/view/topo2/topo2NodePosition.js b/web/gui/src/main/webapp/app/view/topo2/topo2NodePosition.js
index e29c45b..f30401f 100644
--- a/web/gui/src/main/webapp/app/view/topo2/topo2NodePosition.js
+++ b/web/gui/src/main/webapp/app/view/topo2/topo2NodePosition.js
@@ -128,6 +128,12 @@
     }
 
     function coordFromXY(loc) {
+
+        // Something this is wrong in the config
+        if (!t2sls.getWidth() || !t2sls.getHeight()) {
+            return [0, 0];
+        }
+
         var scale = 1000 / t2sls.getWidth(),
             yOffset = (1000 - (t2sls.getHeight() * scale)) / 2;
 
diff --git a/web/gui/src/main/webapp/app/view/topo2/topo2Select.js b/web/gui/src/main/webapp/app/view/topo2/topo2Select.js
index c9972a9..ad99749 100644
--- a/web/gui/src/main/webapp/app/view/topo2/topo2Select.js
+++ b/web/gui/src/main/webapp/app/view/topo2/topo2Select.js
@@ -21,15 +21,15 @@
 (function () {
     'use strict';
 
-    var t2rs;
+    var t2rs, t2zs;
 
     // internal state
     var consumeClick,
         zoomer,
         previousNearestLink;    // previous link to mouse position
 
-    function init(svg, _zoomer_) {
-        zoomer = _zoomer_;
+    function init(svg) {
+        zoomer = t2zs.getZoomer();
         svg.on('mousemove', mouseMoveHandler);
         svg.on('click', mouseClickHandler);
     }
@@ -61,7 +61,6 @@
         var mp = getLogicalMousePosition(this),
             link = computeNearestLink(mp);
 
-        // link.enhance();
         if (link) {
             if (previousNearestLink && previousNearestLink !== link) {
                 previousNearestLink.unenhance();
@@ -158,10 +157,11 @@
 
     angular.module('ovTopo2')
     .factory('Topo2SelectService', [
-        'Topo2RegionService',
-        function (_t2rs_) {
+        'Topo2RegionService', 'Topo2ZoomService',
+        function (_t2rs_, _t2zs_) {
 
             t2rs = _t2rs_;
+            t2zs = _t2zs_;
 
             return {
                 init: init,