From f03526baaf2e04a658b56a41c5b28f33afc8bdbd Mon Sep 17 00:00:00 2001 From: Pavlos Touboulidis Date: Tue, 13 Jan 2015 21:20:16 +0200 Subject: [PATCH] Select the last (top) overlapping object when showing the popup When there are many overlapping objects, pick the last one which is drawn at the top of the others. This is the same way the _getNodeAt() / _getEdgeAt() methods of the SelectionMixin work. --- lib/network/Network.js | 22 ++++++++++++++++------ 1 file changed, 16 insertions(+), 6 deletions(-) diff --git a/lib/network/Network.js b/lib/network/Network.js index 5b8129c0..58e2cf6c 100644 --- a/lib/network/Network.js +++ b/lib/network/Network.js @@ -1336,34 +1336,44 @@ Network.prototype._checkShowPopup = function (pointer) { if (this.popupObj == undefined) { // search the nodes for overlap, select the top one in case of multiple nodes var nodes = this.nodes; + var overlappingNodes = []; for (id in nodes) { if (nodes.hasOwnProperty(id)) { var node = nodes[id]; if (node.isOverlappingWith(obj)) { if (node.getTitle() !== undefined) { - this.popupObj = node; - break; + overlappingNodes.push(id); } - // if you hover over a node, the title of the edge is not supposed to be shown. - nodeUnderCursor = true; } } } + + if (overlappingNodes.length > 0) { + // if there are overlapping nodes, select the last one, this is the + // one which is drawn on top of the others + this.popupObj = this.nodes[overlappingNodes[overlappingNodes.length - 1]]; + // if you hover over a node, the title of the edge is not supposed to be shown. + nodeUnderCursor = true; + } } if (this.popupObj === undefined && nodeUnderCursor == false) { // search the edges for overlap var edges = this.edges; + var overlappingEdges = []; for (id in edges) { if (edges.hasOwnProperty(id)) { var edge = edges[id]; if (edge.connected && (edge.getTitle() !== undefined) && edge.isOverlappingWith(obj)) { - this.popupObj = edge; - break; + overlappingEdges.push(id); } } } + + if (overlappingEdges.length > 0) { + this.popupObj = this.edges[overlappingEdges[overlappingEdges.length - 1]]; + } } if (this.popupObj) {