GUI -- Better cleanup of topo view when it is destroyed.
Change-Id: I038fb43f9a5afc63393583334576d0be81b64f1f
Showing
2 changed files
with
32 additions
and
8 deletions
| ... | @@ -24,7 +24,7 @@ | ... | @@ -24,7 +24,7 @@ |
| 24 | 24 | ||
| 25 | // injected refs | 25 | // injected refs |
| 26 | var $log, fs, sus, is, ts, flash, tis, tms, td3, tss, tts, tos, fltr, tls, | 26 | var $log, fs, sus, is, ts, flash, tis, tms, td3, tss, tts, tos, fltr, tls, |
| 27 | - icfg, uplink; | 27 | + icfg, uplink, svg; |
| 28 | 28 | ||
| 29 | // configuration | 29 | // configuration |
| 30 | var linkConfig = { | 30 | var linkConfig = { |
| ... | @@ -52,8 +52,8 @@ | ... | @@ -52,8 +52,8 @@ |
| 52 | lookup: {}, | 52 | lookup: {}, |
| 53 | revLinkToKey: {} | 53 | revLinkToKey: {} |
| 54 | }, | 54 | }, |
| 55 | - lu = network.lookup, // shorthand | 55 | + lu, // shorthand for lookup |
| 56 | - rlk = network.revLinkToKey, | 56 | + rlk, // shorthand for revLinktoKey |
| 57 | showHosts = false, // whether hosts are displayed | 57 | showHosts = false, // whether hosts are displayed |
| 58 | showOffline = true, // whether offline devices are displayed | 58 | showOffline = true, // whether offline devices are displayed |
| 59 | nodeLock = false, // whether nodes can be dragged or not (locked) | 59 | nodeLock = false, // whether nodes can be dragged or not (locked) |
| ... | @@ -595,9 +595,10 @@ | ... | @@ -595,9 +595,10 @@ |
| 595 | }; | 595 | }; |
| 596 | 596 | ||
| 597 | function tick() { | 597 | function tick() { |
| 598 | - node.attr(tickStuff.nodeAttr); | 598 | + // guard against null (which can happen when our view pages out)... |
| 599 | - link.attr(tickStuff.linkAttr); | 599 | + if (node) node.attr(tickStuff.nodeAttr); |
| 600 | - linkLabel.attr(tickStuff.linkLabelAttr); | 600 | + if (link) link.attr(tickStuff.linkAttr); |
| 601 | + if (linkLabel) linkLabel.attr(tickStuff.linkLabelAttr); | ||
| 601 | } | 602 | } |
| 602 | 603 | ||
| 603 | 604 | ||
| ... | @@ -780,9 +781,13 @@ | ... | @@ -780,9 +781,13 @@ |
| 780 | // uplink is the api from the main topo source file | 781 | // uplink is the api from the main topo source file |
| 781 | // dim is the initial dimensions of the SVG as [w,h] | 782 | // dim is the initial dimensions of the SVG as [w,h] |
| 782 | // opts are, well, optional :) | 783 | // opts are, well, optional :) |
| 783 | - function initForce(svg, forceG, _uplink_, _dim_, opts) { | 784 | + function initForce(_svg_, forceG, _uplink_, _dim_, opts) { |
| 784 | uplink = _uplink_; | 785 | uplink = _uplink_; |
| 785 | dim = _dim_; | 786 | dim = _dim_; |
| 787 | + svg = _svg_; | ||
| 788 | + | ||
| 789 | + lu = network.lookup; | ||
| 790 | + rlk = network.revLinkToKey; | ||
| 786 | 791 | ||
| 787 | $log.debug('initForce().. dim = ' + dim); | 792 | $log.debug('initForce().. dim = ' + dim); |
| 788 | 793 | ||
| ... | @@ -824,10 +829,11 @@ | ... | @@ -824,10 +829,11 @@ |
| 824 | dim = _dim_; | 829 | dim = _dim_; |
| 825 | force.size(dim); | 830 | force.size(dim); |
| 826 | tms.newDim(dim); | 831 | tms.newDim(dim); |
| 827 | - // Review -- do we need to nudge the layout ? | ||
| 828 | } | 832 | } |
| 829 | 833 | ||
| 830 | function destroyForce() { | 834 | function destroyForce() { |
| 835 | + force.stop(); | ||
| 836 | + | ||
| 831 | tls.destroyLink(); | 837 | tls.destroyLink(); |
| 832 | fltr.destroyFilter(); | 838 | fltr.destroyFilter(); |
| 833 | tos.destroyOblique(); | 839 | tos.destroyOblique(); |
| ... | @@ -837,6 +843,20 @@ | ... | @@ -837,6 +843,20 @@ |
| 837 | tms.destroyModel(); | 843 | tms.destroyModel(); |
| 838 | ts.removeListener(themeListener); | 844 | ts.removeListener(themeListener); |
| 839 | themeListener = null; | 845 | themeListener = null; |
| 846 | + | ||
| 847 | + // clean up the DOM | ||
| 848 | + svg.selectAll('g').remove(); | ||
| 849 | + svg.selectAll('defs').remove(); | ||
| 850 | + | ||
| 851 | + // clean up internal state | ||
| 852 | + network.nodes = []; | ||
| 853 | + network.links = []; | ||
| 854 | + network.lookup = {}; | ||
| 855 | + network.revLinkToKey = {}; | ||
| 856 | + | ||
| 857 | + linkG = linkLabelG = nodeG = portLabelG = null; | ||
| 858 | + link = linkLabel = node = null; | ||
| 859 | + force = drag = null; | ||
| 840 | } | 860 | } |
| 841 | 861 | ||
| 842 | return { | 862 | return { | ... | ... |
| ... | @@ -303,6 +303,10 @@ | ... | @@ -303,6 +303,10 @@ |
| 303 | 303 | ||
| 304 | ps.destroyPanel(idIns); | 304 | ps.destroyPanel(idIns); |
| 305 | oiBox = null; | 305 | oiBox = null; |
| 306 | + | ||
| 307 | + onosInstances = {}; | ||
| 308 | + onosOrder = []; | ||
| 309 | + oiShowMaster = false; | ||
| 306 | } | 310 | } |
| 307 | 311 | ||
| 308 | // ========================== | 312 | // ========================== | ... | ... |
-
Please register or login to post a comment