Simon Hunt
Committed by Brian O'Connor

ONOS-1419 - Fix to allow nodes to be selected in the Oblique View.

(NOTE: still experimental feature, but it works sufficiently)

Change-Id: I4437180a9c34656effa0735288818ea0a05779ac
...@@ -48,10 +48,6 @@ ...@@ -48,10 +48,6 @@
48 return {x: mx, y: my}; 48 return {x: mx, y: my};
49 } 49 }
50 50
51 - function computeNearestLink(mouse) {
52 - var proximity = 30 / api.zoomer.scale(),
53 - nearest = null,
54 - minDist;
55 51
56 function sq(x) { return x * x; } 52 function sq(x) { return x * x; }
57 53
...@@ -59,6 +55,41 @@ ...@@ -59,6 +55,41 @@
59 return Math.sqrt(sq(p.x - m.x) + sq(p.y - m.y)); 55 return Math.sqrt(sq(p.x - m.x) + sq(p.y - m.y));
60 } 56 }
61 57
58 + function prox(dist) {
59 + return dist / api.zoomer.scale();
60 + }
61 +
62 + function computeNearestNode(mouse) {
63 + var proximity = prox(30),
64 + nearest = null,
65 + minDist;
66 +
67 + if (network.nodes.length) {
68 + minDist = proximity * 2;
69 +
70 + network.nodes.forEach(function (d) {
71 + var dist;
72 +
73 + if (!api.showHosts() && d.class === 'host') {
74 + return; // skip hidden hosts
75 + }
76 +
77 + dist = mdist({x: d.x, y: d.y}, mouse);
78 + if (dist < minDist && dist < proximity) {
79 + minDist = dist;
80 + nearest = d;
81 + }
82 + });
83 + }
84 + return nearest;
85 + }
86 +
87 +
88 + function computeNearestLink(mouse) {
89 + var proximity = prox(30),
90 + nearest = null,
91 + minDist;
92 +
62 function pdrop(line, mouse) { 93 function pdrop(line, mouse) {
63 var x1 = line.x1, 94 var x1 = line.x1,
64 y1 = line.y1, 95 y1 = line.y1,
...@@ -229,14 +260,20 @@ ...@@ -229,14 +260,20 @@
229 } 260 }
230 261
231 function mouseClickHandler() { 262 function mouseClickHandler() {
232 - var mp, link; 263 + var mp, link, node;
233 264
234 if (!tss.clickConsumed()) { 265 if (!tss.clickConsumed()) {
235 mp = getLogicalMousePosition(this); 266 mp = getLogicalMousePosition(this);
267 + node = computeNearestNode(mp);
268 + if (node) {
269 + $log.debug('found nearest node:', node.labels[1]);
270 + tss.selectObject(node);
271 + } else {
236 link = computeNearestLink(mp); 272 link = computeNearestLink(mp);
237 selectLink(link); 273 selectLink(link);
238 } 274 }
239 } 275 }
276 + }
240 277
241 278
242 // ====================== 279 // ======================
......
...@@ -88,14 +88,15 @@ ...@@ -88,14 +88,15 @@
88 88
89 function selectObject(obj) { 89 function selectObject(obj) {
90 var el = this, 90 var el = this,
91 - ev = d3.event.sourceEvent, 91 + nodeEv = el && el.tagName === 'g',
92 + ev = d3.event.sourceEvent || {},
92 n; 93 n;
93 94
94 if (api.zoomingOrPanning(ev)) { 95 if (api.zoomingOrPanning(ev)) {
95 return; 96 return;
96 } 97 }
97 98
98 - if (el) { 99 + if (nodeEv) {
99 n = d3.select(el); 100 n = d3.select(el);
100 } else { 101 } else {
101 api.node().each(function (d) { 102 api.node().each(function (d) {
...@@ -106,7 +107,9 @@ ...@@ -106,7 +107,9 @@
106 } 107 }
107 if (!n) return; 108 if (!n) return;
108 109
110 + if (nodeEv) {
109 consumeClick = true; 111 consumeClick = true;
112 + }
110 api.deselectLink(); 113 api.deselectLink();
111 114
112 if (ev.shiftKey && n.classed('selected')) { 115 if (ev.shiftKey && n.classed('selected')) {
......