Simon Hunt

GUI -- TopoView - working on mouse gestures - drag, click on nodes; mouseover,mouseout (WIP).

Change-Id: I2ecd4f805267fe72685381eb297a3d4cbbbd360a
...@@ -112,16 +112,14 @@ ...@@ -112,16 +112,14 @@
112 // consider this the same as a 'click' 112 // consider this the same as a 'click'
113 // (selection of a node) 113 // (selection of a node)
114 if (clickEnabled()) { 114 if (clickEnabled()) {
115 - selectCb(d, this); 115 + selectCb.call(this, d);
116 - // TODO: set 'this' context instead of param
117 } 116 }
118 } 117 }
119 d.fixed &= ~6; 118 d.fixed &= ~6;
120 119
121 // hook at the end of a drag gesture 120 // hook at the end of a drag gesture
122 if (dragEnabled()) { 121 if (dragEnabled()) {
123 - atDragEnd(d, this); 122 + atDragEnd.call(this, d);
124 - // TODO: set 'this' context instead of param
125 } 123 }
126 } 124 }
127 }); 125 });
......
...@@ -61,8 +61,7 @@ ...@@ -61,8 +61,7 @@
61 } 61 }
62 62
63 .light #ov-topo svg #topo-map { 63 .light #ov-topo svg #topo-map {
64 - stroke: #ddd; 64 + stroke: #eee;
65 - /*stroke: #88b;*/
66 } 65 }
67 .dark #ov-topo svg #topo-map { 66 .dark #ov-topo svg #topo-map {
68 stroke: #444; 67 stroke: #444;
......
...@@ -54,7 +54,7 @@ ...@@ -54,7 +54,7 @@
54 //X: [toggleNodeLock, 'Lock / unlock node positions'], 54 //X: [toggleNodeLock, 'Lock / unlock node positions'],
55 //Z: [toggleOblique, 'Toggle oblique view (Experimental)'], 55 //Z: [toggleOblique, 'Toggle oblique view (Experimental)'],
56 L: [tfs.cycleDeviceLabels, 'Cycle device labels'], 56 L: [tfs.cycleDeviceLabels, 'Cycle device labels'],
57 - //U: [unpin, 'Unpin node (hover mouse over)'], 57 + U: [tfs.unpin, 'Unpin node (hover mouse over)'],
58 R: [resetZoom, 'Reset pan / zoom'], 58 R: [resetZoom, 'Reset pan / zoom'],
59 59
60 //V: [showRelatedIntentsAction, 'Show all related intents'], 60 //V: [showRelatedIntentsAction, 'Show all related intents'],
......
...@@ -75,7 +75,9 @@ ...@@ -75,7 +75,9 @@
75 showHosts = true, // whether hosts are displayed 75 showHosts = true, // whether hosts are displayed
76 showOffline = true, // whether offline devices are displayed 76 showOffline = true, // whether offline devices are displayed
77 oblique = false, // whether we are in the oblique view 77 oblique = false, // whether we are in the oblique view
78 - width, height; 78 + nodeLock = false, // whether nodes can be dragged or not (locked)
79 + width, height, // the width and height of the force layout
80 + hovered; // the node over which the mouse is hovering
79 81
80 // SVG elements; 82 // SVG elements;
81 var linkG, linkLabelG, nodeG; 83 var linkG, linkLabelG, nodeG;
...@@ -146,7 +148,7 @@ ...@@ -146,7 +148,7 @@
146 wasOnline = d.online; 148 wasOnline = d.online;
147 angular.extend(d, data); 149 angular.extend(d, data);
148 if (positionNode(d, true)) { 150 if (positionNode(d, true)) {
149 - sendUpdateMeta(d, true); 151 + sendUpdateMeta(d);
150 } 152 }
151 updateNodes(); 153 updateNodes();
152 if (wasOnline !== d.online) { 154 if (wasOnline !== d.online) {
...@@ -210,7 +212,7 @@ ...@@ -210,7 +212,7 @@
210 if (d) { 212 if (d) {
211 angular.extend(d, data); 213 angular.extend(d, data);
212 if (positionNode(d, true)) { 214 if (positionNode(d, true)) {
213 - sendUpdateMeta(d, true); 215 + sendUpdateMeta(d);
214 } 216 }
215 updateNodes(); 217 updateNodes();
216 } else { 218 } else {
...@@ -557,11 +559,13 @@ ...@@ -557,11 +559,13 @@
557 } 559 }
558 560
559 561
560 - function sendUpdateMeta(d, store) { 562 + function sendUpdateMeta(d, clearPos) {
561 var metaUi = {}, 563 var metaUi = {},
562 ll; 564 ll;
563 565
564 - if (store) { 566 + // if we are not clearing the position data (unpinning),
567 + // attach the x, y, longitude, latitude...
568 + if (!clearPos) {
565 ll = lngLatFromCoord([d.x, d.y]); 569 ll = lngLatFromCoord([d.x, d.y]);
566 metaUi = { 570 metaUi = {
567 x: d.x, 571 x: d.x,
...@@ -578,6 +582,9 @@ ...@@ -578,6 +582,9 @@
578 }); 582 });
579 } 583 }
580 584
585 + function requestTrafficForMode() {
586 + $log.debug('TODO: requestTrafficForMode()...');
587 + }
581 588
582 // ========================== 589 // ==========================
583 // === Devices and hosts - helper functions 590 // === Devices and hosts - helper functions
...@@ -589,7 +596,7 @@ ...@@ -589,7 +596,7 @@
589 596
590 function lngLatFromCoord(coord) { 597 function lngLatFromCoord(coord) {
591 var p = uplink.projection(); 598 var p = uplink.projection();
592 - return p ? p.invert([coord.x, coord.y]) : [0, 0]; 599 + return p ? p.invert(coord) : [0, 0];
593 } 600 }
594 601
595 function positionNode(node, forUpdate) { 602 function positionNode(node, forUpdate) {
...@@ -744,12 +751,24 @@ ...@@ -744,12 +751,24 @@
744 751
745 function nodeMouseOver(m) { 752 function nodeMouseOver(m) {
746 // TODO 753 // TODO
747 - $log.debug("TODO nodeMouseOver()...", m); 754 + if (!m.dragStarted) {
755 + $log.debug("MouseOver()...", m);
756 + if (hovered != m) {
757 + hovered = m;
758 + requestTrafficForMode();
759 + }
760 + }
748 } 761 }
749 762
750 function nodeMouseOut(m) { 763 function nodeMouseOut(m) {
751 // TODO 764 // TODO
752 - $log.debug("TODO nodeMouseOut()...", m); 765 + if (!m.dragStarted) {
766 + if (hovered) {
767 + hovered = null;
768 + requestTrafficForMode();
769 + }
770 + $log.debug("MouseOut()...", m);
771 + }
753 } 772 }
754 773
755 774
...@@ -873,6 +892,16 @@ ...@@ -873,6 +892,16 @@
873 }); 892 });
874 } 893 }
875 894
895 + function unpin() {
896 + if (hovered) {
897 + sendUpdateMeta(hovered, true);
898 + hovered.fixed = false;
899 + hovered.el.classed('fixed', false);
900 + fResume();
901 + }
902 + }
903 +
904 +
876 // ========================================== 905 // ==========================================
877 906
878 var dCol = { 907 var dCol = {
...@@ -1297,11 +1326,33 @@ ...@@ -1297,11 +1326,33 @@
1297 // ========================== 1326 // ==========================
1298 // === MOUSE GESTURE HANDLERS 1327 // === MOUSE GESTURE HANDLERS
1299 1328
1300 - // FIXME: 1329 + function selectCb(d) {
1301 - function selectCb() { } 1330 + // this is the selected node
1302 - function atDragEnd() {} 1331 + $log.debug("\n\n\nSelect Object: ");
1303 - function dragEnabled() {} 1332 + $log.debug("d is ", d);
1304 - function clickEnabled() {} 1333 + $log.debug("this is ", this);
1334 + $log.debug('\n\n');
1335 + }
1336 +
1337 + function atDragEnd(d) {
1338 + // once we've finished moving, pin the node in position
1339 + d.fixed = true;
1340 + d3.select(this).classed('fixed', true);
1341 + sendUpdateMeta(d);
1342 + }
1343 +
1344 + // predicate that indicates when dragging is active
1345 + function dragEnabled() {
1346 + var ev = d3.event.sourceEvent;
1347 + // nodeLock means we aren't allowing nodes to be dragged...
1348 + // meta or alt key pressed means we are zooming/panning...
1349 + return !nodeLock && !(ev.metaKey || ev.altKey);
1350 + }
1351 +
1352 + // predicate that indicates when clicking is active
1353 + function clickEnabled() {
1354 + return true;
1355 + }
1305 1356
1306 1357
1307 // ========================== 1358 // ==========================
...@@ -1373,6 +1424,7 @@ ...@@ -1373,6 +1424,7 @@
1373 toggleHosts: toggleHosts, 1424 toggleHosts: toggleHosts,
1374 toggleOffline: toggleOffline, 1425 toggleOffline: toggleOffline,
1375 cycleDeviceLabels: cycleDeviceLabels, 1426 cycleDeviceLabels: cycleDeviceLabels,
1427 + unpin: unpin,
1376 1428
1377 addDevice: addDevice, 1429 addDevice: addDevice,
1378 updateDevice: updateDevice, 1430 updateDevice: updateDevice,
......
...@@ -35,7 +35,7 @@ describe('factory: view/topo/topoForce.js', function() { ...@@ -35,7 +35,7 @@ describe('factory: view/topo/topoForce.js', function() {
35 it('should define api functions', function () { 35 it('should define api functions', function () {
36 expect(fs.areFunctions(tfs, [ 36 expect(fs.areFunctions(tfs, [
37 'initForce', 'resize', 'updateDeviceColors', 37 'initForce', 'resize', 'updateDeviceColors',
38 - 'toggleHosts', 'toggleOffline','cycleDeviceLabels', 38 + 'toggleHosts', 'toggleOffline','cycleDeviceLabels', 'unpin',
39 'addDevice', 'updateDevice', 'removeDevice', 39 'addDevice', 'updateDevice', 'removeDevice',
40 'addHost', 'updateHost', 'removeHost', 40 'addHost', 'updateHost', 'removeHost',
41 'addLink', 'updateLink', 'removeLink' 41 'addLink', 'updateLink', 'removeLink'
......