Bri Prebilic Cole
Committed by Gerrit Code Review

GUI -- Topo force layout bug fixes. ONOS-2398 investigated and partially fixed, …

…but also discovered there is a problem in the d3 library.

Change-Id: I4afbc1cc296eec3ad7bf8e47a59b1747ccce1481
...@@ -58,7 +58,6 @@ ...@@ -58,7 +58,6 @@
58 showHosts = false, // whether hosts are displayed 58 showHosts = false, // whether hosts are displayed
59 showOffline = true, // whether offline devices are displayed 59 showOffline = true, // whether offline devices are displayed
60 nodeLock = false, // whether nodes can be dragged or not (locked) 60 nodeLock = false, // whether nodes can be dragged or not (locked)
61 - fTimer, // timer for delayed force layout
62 fNodesTimer, // timer for delayed nodes update 61 fNodesTimer, // timer for delayed nodes update
63 fLinksTimer, // timer for delayed links update 62 fLinksTimer, // timer for delayed links update
64 dim, // the dimensions of the force layout [w,h] 63 dim, // the dimensions of the force layout [w,h]
...@@ -118,7 +117,6 @@ ...@@ -118,7 +117,6 @@
118 network.nodes.push(d); 117 network.nodes.push(d);
119 lu[id] = d; 118 lu[id] = d;
120 updateNodes(); 119 updateNodes();
121 - fStart();
122 } 120 }
123 121
124 function updateDevice(data) { 122 function updateDevice(data) {
...@@ -172,8 +170,6 @@ ...@@ -172,8 +170,6 @@
172 lu[d.egress] = lnk; 170 lu[d.egress] = lnk;
173 updateLinks(); 171 updateLinks();
174 } 172 }
175 -
176 - fStart();
177 } 173 }
178 174
179 function updateHost(data) { 175 function updateHost(data) {
...@@ -219,7 +215,6 @@ ...@@ -219,7 +215,6 @@
219 aggregateLink(d, data); 215 aggregateLink(d, data);
220 lu[d.key] = d; 216 lu[d.key] = d;
221 updateLinks(); 217 updateLinks();
222 - fStart();
223 } 218 }
224 } 219 }
225 220
...@@ -327,7 +322,6 @@ ...@@ -327,7 +322,6 @@
327 // remove from lookup cache 322 // remove from lookup cache
328 delete lu[removed[0].key]; 323 delete lu[removed[0].key];
329 updateLinks(); 324 updateLinks();
330 - fResume();
331 } 325 }
332 } 326 }
333 327
...@@ -349,12 +343,12 @@ ...@@ -349,12 +343,12 @@
349 // NOTE: upd is false if we were called from removeDeviceElement() 343 // NOTE: upd is false if we were called from removeDeviceElement()
350 if (upd) { 344 if (upd) {
351 updateNodes(); 345 updateNodes();
352 - fResume();
353 } 346 }
354 } 347 }
355 348
356 function removeDeviceElement(d) { 349 function removeDeviceElement(d) {
357 - var id = d.id; 350 + var id = d.id,
351 + idx;
358 // first, remove associated hosts and links.. 352 // first, remove associated hosts and links..
359 tms.findAttachedHosts(id).forEach(removeHostElement); 353 tms.findAttachedHosts(id).forEach(removeHostElement);
360 tms.findAttachedLinks(id).forEach(removeLinkElement); 354 tms.findAttachedLinks(id).forEach(removeLinkElement);
...@@ -362,8 +356,10 @@ ...@@ -362,8 +356,10 @@
362 // remove from lookup cache 356 // remove from lookup cache
363 delete lu[id]; 357 delete lu[id];
364 // remove from nodes array 358 // remove from nodes array
365 - var idx = fs.find(id, network.nodes); 359 + idx = fs.find(id, network.nodes);
366 - network.nodes.splice(idx, 1); 360 + if (idx > -1) {
361 + network.nodes.splice(idx, 1);
362 + }
367 363
368 if (!network.nodes.length) { 364 if (!network.nodes.length) {
369 uplink.showNoDevs(true); 365 uplink.showNoDevs(true);
...@@ -371,7 +367,6 @@ ...@@ -371,7 +367,6 @@
371 367
372 // remove from SVG 368 // remove from SVG
373 updateNodes(); 369 updateNodes();
374 - fResume();
375 } 370 }
376 371
377 function updateHostVisibility() { 372 function updateHostVisibility() {
...@@ -526,6 +521,7 @@ ...@@ -526,6 +521,7 @@
526 } 521 }
527 522
528 function _updateNodes() { 523 function _updateNodes() {
524 + force.stop();
529 // select all the nodes in the layout: 525 // select all the nodes in the layout:
530 node = nodeG.selectAll('.node') 526 node = nodeG.selectAll('.node')
531 .data(network.nodes, function (d) { return d.id; }); 527 .data(network.nodes, function (d) { return d.id; });
...@@ -540,11 +536,7 @@ ...@@ -540,11 +536,7 @@
540 .attr({ 536 .attr({
541 id: function (d) { return sus.safeId(d.id); }, 537 id: function (d) { return sus.safeId(d.id); },
542 class: mkSvgClass, 538 class: mkSvgClass,
543 - transform: function (d) { 539 + transform: function (d) { return sus.translate(d.x, d.y); },
544 - // sometimes says d.x and d.y are NaN?
545 - // I have a feeling it's a timing issue
546 - return sus.translate(d.x, d.y);
547 - },
548 opacity: 0 540 opacity: 0
549 }) 541 })
550 .call(drag) 542 .call(drag)
...@@ -572,6 +564,7 @@ ...@@ -572,6 +564,7 @@
572 // exiting node specifics: 564 // exiting node specifics:
573 exiting.filter('.host').each(td3.hostExit); 565 exiting.filter('.host').each(td3.hostExit);
574 exiting.filter('.device').each(td3.deviceExit); 566 exiting.filter('.device').each(td3.deviceExit);
567 + fStart();
575 } 568 }
576 569
577 // ========================== 570 // ==========================
...@@ -668,13 +661,11 @@ ...@@ -668,13 +661,11 @@
668 661
669 function _updateLinks() { 662 function _updateLinks() {
670 var th = ts.theme(); 663 var th = ts.theme();
664 + force.stop();
671 665
672 link = linkG.selectAll('.link') 666 link = linkG.selectAll('.link')
673 .data(network.links, function (d) { return d.key; }); 667 .data(network.links, function (d) { return d.key; });
674 668
675 - // This seems to do nothing? I've only triggered it on timeout errors
676 - // when adding links, link var is empty because there aren't any links
677 - // when removing links, link var is empty already
678 // operate on existing links: 669 // operate on existing links:
679 link.each(function (d) { 670 link.each(function (d) {
680 // this is supposed to be an existing link, but we have observed 671 // this is supposed to be an existing link, but we have observed
...@@ -723,6 +714,7 @@ ...@@ -723,6 +714,7 @@
723 }) 714 })
724 .style('opacity', 0.0) 715 .style('opacity', 0.0)
725 .remove(); 716 .remove();
717 + fStart();
726 } 718 }
727 719
728 720
...@@ -737,13 +729,8 @@ ...@@ -737,13 +729,8 @@
737 729
738 function fStart() { 730 function fStart() {
739 if (!tos.isOblique()) { 731 if (!tos.isOblique()) {
740 - if (fTimer) { 732 + $log.debug("Starting force-layout");
741 - $timeout.cancel(fTimer); 733 + force.start();
742 - }
743 - fTimer = $timeout(function () {
744 - $log.debug("Starting force-layout");
745 - force.start();
746 - }, 200);
747 } 734 }
748 } 735 }
749 736
...@@ -769,15 +756,15 @@ ...@@ -769,15 +756,15 @@
769 756
770 function tick() { 757 function tick() {
771 // guard against null (which can happen when our view pages out)... 758 // guard against null (which can happen when our view pages out)...
772 - if (node) { 759 + if (node && node.size()) {
773 node.attr(tickStuff.nodeAttr); 760 node.attr(tickStuff.nodeAttr);
774 } 761 }
775 - if (link) { 762 + if (link && link.size()) {
776 link.call(calcPosition) 763 link.call(calcPosition)
777 .attr(tickStuff.linkAttr); 764 .attr(tickStuff.linkAttr);
778 td3.applyNumLinkLabels(linkNums, numLinkLblsG); 765 td3.applyNumLinkLabels(linkNums, numLinkLblsG);
779 } 766 }
780 - if (linkLabel) { 767 + if (linkLabel && linkLabel.size()) {
781 linkLabel.attr(tickStuff.linkLabelAttr); 768 linkLabel.attr(tickStuff.linkLabelAttr);
782 } 769 }
783 } 770 }
...@@ -1050,9 +1037,6 @@ ...@@ -1050,9 +1037,6 @@
1050 force = drag = null; 1037 force = drag = null;
1051 1038
1052 // clean up $timeout promises 1039 // clean up $timeout promises
1053 - if (fTimer) {
1054 - $timeout.cancel(fTimer);
1055 - }
1056 if (fNodesTimer) { 1040 if (fNodesTimer) {
1057 $timeout.cancel(fNodesTimer); 1041 $timeout.cancel(fNodesTimer);
1058 } 1042 }
......