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,16 +48,47 @@ ...@@ -48,16 +48,47 @@
48 return {x: mx, y: my}; 48 return {x: mx, y: my};
49 } 49 }
50 50
51 - function computeNearestLink(mouse) { 51 +
52 - var proximity = 30 / api.zoomer.scale(), 52 + function sq(x) { return x * x; }
53 +
54 + function mdist(p, m) {
55 + return Math.sqrt(sq(p.x - m.x) + sq(p.y - m.y));
56 + }
57 +
58 + function prox(dist) {
59 + return dist / api.zoomer.scale();
60 + }
61 +
62 + function computeNearestNode(mouse) {
63 + var proximity = prox(30),
53 nearest = null, 64 nearest = null,
54 minDist; 65 minDist;
55 66
56 - function sq(x) { return x * x; } 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 + }
57 76
58 - function mdist(p, m) { 77 + dist = mdist({x: d.x, y: d.y}, mouse);
59 - return Math.sqrt(sq(p.x - m.x) + sq(p.y - m.y)); 78 + if (dist < minDist && dist < proximity) {
79 + minDist = dist;
80 + nearest = d;
81 + }
82 + });
60 } 83 }
84 + return nearest;
85 + }
86 +
87 +
88 + function computeNearestLink(mouse) {
89 + var proximity = prox(30),
90 + nearest = null,
91 + minDist;
61 92
62 function pdrop(line, mouse) { 93 function pdrop(line, mouse) {
63 var x1 = line.x1, 94 var x1 = line.x1,
...@@ -229,12 +260,18 @@ ...@@ -229,12 +260,18 @@
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);
236 - link = computeNearestLink(mp); 267 + node = computeNearestNode(mp);
237 - selectLink(link); 268 + if (node) {
269 + $log.debug('found nearest node:', node.labels[1]);
270 + tss.selectObject(node);
271 + } else {
272 + link = computeNearestLink(mp);
273 + selectLink(link);
274 + }
238 } 275 }
239 } 276 }
240 277
......
...@@ -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
109 - consumeClick = true; 110 + if (nodeEv) {
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')) {
......