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 @@
return {x: mx, y: my};
}
function computeNearestLink(mouse) {
var proximity = 30 / api.zoomer.scale(),
function sq(x) { return x * x; }
function mdist(p, m) {
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;
function sq(x) { return x * x; }
if (network.nodes.length) {
minDist = proximity * 2;
network.nodes.forEach(function (d) {
var dist;
if (!api.showHosts() && d.class === 'host') {
return; // skip hidden hosts
}
function mdist(p, m) {
return Math.sqrt(sq(p.x - m.x) + sq(p.y - m.y));
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,
......@@ -229,12 +260,18 @@
}
function mouseClickHandler() {
var mp, link;
var mp, link, node;
if (!tss.clickConsumed()) {
mp = getLogicalMousePosition(this);
link = computeNearestLink(mp);
selectLink(link);
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;
consumeClick = true;
if (nodeEv) {
consumeClick = true;
}
api.deselectLink();
if (ev.shiftKey && n.classed('selected')) {
......