Simon Hunt

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 @@
return {x: mx, y: my};
}
function computeNearestLink(mouse) {
var proximity = 30 / api.zoomer.scale(),
nearest = null,
minDist;
function sq(x) { return x * x; }
......@@ -59,6 +55,41 @@
return Math.sqrt(sq(p.x - m.x) + sq(p.y - m.y));
}
function prox(dist) {
return dist / api.zoomer.scale();
}
function computeNearestNode(mouse) {
var proximity = prox(30),
nearest = null,
minDist;
if (network.nodes.length) {
minDist = proximity * 2;
network.nodes.forEach(function (d) {
var dist;
if (!api.showHosts() && d.class === 'host') {
return; // skip hidden hosts
}
dist = mdist({x: d.x, y: d.y}, mouse);
if (dist < minDist && dist < proximity) {
minDist = dist;
nearest = d;
}
});
}
return nearest;
}
function computeNearestLink(mouse) {
var proximity = prox(30),
nearest = null,
minDist;
function pdrop(line, mouse) {
var x1 = line.x1,
y1 = line.y1,
......@@ -229,14 +260,20 @@
}
function mouseClickHandler() {
var mp, link;
var mp, link, node;
if (!tss.clickConsumed()) {
mp = getLogicalMousePosition(this);
node = computeNearestNode(mp);
if (node) {
$log.debug('found nearest node:', node.labels[1]);
tss.selectObject(node);
} else {
link = computeNearestLink(mp);
selectLink(link);
}
}
}
// ======================
......
......@@ -88,14 +88,15 @@
function selectObject(obj) {
var el = this,
ev = d3.event.sourceEvent,
nodeEv = el && el.tagName === 'g',
ev = d3.event.sourceEvent || {},
n;
if (api.zoomingOrPanning(ev)) {
return;
}
if (el) {
if (nodeEv) {
n = d3.select(el);
} else {
api.node().each(function (d) {
......@@ -106,7 +107,9 @@
}
if (!n) return;
if (nodeEv) {
consumeClick = true;
}
api.deselectLink();
if (ev.shiftKey && n.classed('selected')) {
......