Simon Hunt

GUI -- TopoView - implemented show/hide background map ('B' keystroke)

- reworked SvgUtilService.makeVisible() to be dual-purpose .visible(el, [b]) method.

Change-Id: I8e68994627d1022066cdc9dcbed006675431d91a
...@@ -235,12 +235,16 @@ ...@@ -235,12 +235,16 @@
235 return s.replace(/px$/,''); 235 return s.replace(/px$/,'');
236 } 236 }
237 237
238 + function safeId(s) {
239 + return s.replace(/[^a-z0-9]/gi, '-');
240 + }
241 +
238 function makeVisible(el, b) { 242 function makeVisible(el, b) {
239 el.style('visibility', (b ? 'visible' : 'hidden')); 243 el.style('visibility', (b ? 'visible' : 'hidden'));
240 } 244 }
241 245
242 - function safeId(s) { 246 + function isVisible(el) {
243 - return s.replace(/[^a-z0-9]/gi, '-'); 247 + return el.style('visibility') === 'visible';
244 } 248 }
245 249
246 return { 250 return {
...@@ -249,8 +253,14 @@ ...@@ -249,8 +253,14 @@
249 cat7: cat7, 253 cat7: cat7,
250 translate: translate, 254 translate: translate,
251 stripPx: stripPx, 255 stripPx: stripPx,
252 - makeVisible: makeVisible, 256 + safeId: safeId,
253 - safeId: safeId 257 + visible: function (el, x) {
258 + if (x === undefined) {
259 + return isVisible(el);
260 + } else {
261 + makeVisible(el, x);
262 + }
263 + }
254 }; 264 };
255 }]); 265 }]);
256 }()); 266 }());
......
...@@ -48,7 +48,7 @@ ...@@ -48,7 +48,7 @@
48 48
49 H: [tfs.toggleHosts, 'Toggle host visibility'], 49 H: [tfs.toggleHosts, 'Toggle host visibility'],
50 M: [tfs.toggleOffline, 'Toggle offline visibility'], 50 M: [tfs.toggleOffline, 'Toggle offline visibility'],
51 - //B: [toggleBg, 'Toggle background image'], 51 + B: [toggleMap, 'Toggle background map'],
52 //P: togglePorts, 52 //P: togglePorts,
53 53
54 //X: [toggleNodeLock, 'Lock / unlock node positions'], 54 //X: [toggleNodeLock, 'Lock / unlock node positions'],
...@@ -94,6 +94,10 @@ ...@@ -94,6 +94,10 @@
94 tfs.updateDeviceColors(); 94 tfs.updateDeviceColors();
95 } 95 }
96 96
97 + function toggleMap() {
98 + sus.visible(mapG, !sus.visible(mapG));
99 + }
100 +
97 function resetZoom() { 101 function resetZoom() {
98 zoomer.reset(); 102 zoomer.reset();
99 } 103 }
...@@ -184,7 +188,7 @@ ...@@ -184,7 +188,7 @@
184 } 188 }
185 189
186 function showNoDevs(b) { 190 function showNoDevs(b) {
187 - sus.makeVisible(noDevsLayer, b); 191 + sus.visible(noDevsLayer, b);
188 } 192 }
189 193
190 function showCallibrationPoints() { 194 function showCallibrationPoints() {
......
...@@ -365,21 +365,21 @@ ...@@ -365,21 +365,21 @@
365 } 365 }
366 366
367 function updateHostVisibility() { 367 function updateHostVisibility() {
368 - sus.makeVisible(nodeG.selectAll('.host'), showHosts); 368 + sus.visible(nodeG.selectAll('.host'), showHosts);
369 - sus.makeVisible(linkG.selectAll('.hostLink'), showHosts); 369 + sus.visible(linkG.selectAll('.hostLink'), showHosts);
370 } 370 }
371 371
372 function updateOfflineVisibility(dev) { 372 function updateOfflineVisibility(dev) {
373 function updDev(d, show) { 373 function updDev(d, show) {
374 - sus.makeVisible(d.el, show); 374 + sus.visible(d.el, show);
375 375
376 tms.findAttachedLinks(d.id).forEach(function (link) { 376 tms.findAttachedLinks(d.id).forEach(function (link) {
377 b = show && ((link.type() !== 'hostLink') || showHosts); 377 b = show && ((link.type() !== 'hostLink') || showHosts);
378 - sus.makeVisible(link.el, b); 378 + sus.visible(link.el, b);
379 }); 379 });
380 tms.findAttachedHosts(d.id).forEach(function (host) { 380 tms.findAttachedHosts(d.id).forEach(function (host) {
381 b = show && showHosts; 381 b = show && showHosts;
382 - sus.makeVisible(host.el, b); 382 + sus.visible(host.el, b);
383 }); 383 });
384 } 384 }
385 385
...@@ -721,7 +721,7 @@ ...@@ -721,7 +721,7 @@
721 textDy = r + 10; 721 textDy = r + 10;
722 722
723 d.el = node; 723 d.el = node;
724 - sus.makeVisible(node, showHosts); 724 + sus.visible(node, showHosts);
725 725
726 is.addHostIcon(node, r, gid); 726 is.addHostIcon(node, r, gid);
727 727
...@@ -849,7 +849,7 @@ ...@@ -849,7 +849,7 @@
849 d.el = link; 849 d.el = link;
850 restyleLinkElement(d); 850 restyleLinkElement(d);
851 if (d.type() === 'hostLink') { 851 if (d.type() === 'hostLink') {
852 - sus.makeVisible(link, showHosts); 852 + sus.visible(link, showHosts);
853 } 853 }
854 } 854 }
855 855
......
...@@ -41,7 +41,7 @@ describe('factory: fw/svg/svgUtil.js', function() { ...@@ -41,7 +41,7 @@ describe('factory: fw/svg/svgUtil.js', function() {
41 it('should define api functions', function () { 41 it('should define api functions', function () {
42 expect(fs.areFunctions(sus, [ 42 expect(fs.areFunctions(sus, [
43 'createDragBehavior', 'loadGlow', 'cat7', 'translate', 'stripPx', 43 'createDragBehavior', 'loadGlow', 'cat7', 'translate', 'stripPx',
44 - 'makeVisible', 'safeId' 44 + 'safeId', 'visible'
45 ])).toBeTruthy(); 45 ])).toBeTruthy();
46 }); 46 });
47 47
...@@ -114,15 +114,17 @@ describe('factory: fw/svg/svgUtil.js', function() { ...@@ -114,15 +114,17 @@ describe('factory: fw/svg/svgUtil.js', function() {
114 expect(sus.stripPx('4px')).toEqual('4'); 114 expect(sus.stripPx('4px')).toEqual('4');
115 }); 115 });
116 116
117 - // === makeVisible() 117 + // === visible()
118 118
119 it('should hide and show an element', function () { 119 it('should hide and show an element', function () {
120 var r = svg.append('rect'); 120 var r = svg.append('rect');
121 121
122 - sus.makeVisible(r, false); 122 + sus.visible(r, false);
123 expect(r.style('visibility')).toEqual('hidden'); 123 expect(r.style('visibility')).toEqual('hidden');
124 + expect(sus.visible(r)).toBe(false);
124 125
125 - sus.makeVisible(r, true); 126 + sus.visible(r, true);
126 expect(r.style('visibility')).toEqual('visible'); 127 expect(r.style('visibility')).toEqual('visible');
128 + expect(sus.visible(r)).toBe(true);
127 }); 129 });
128 }); 130 });
......