From 9b2a24c4373ad678f32a7e7e681e496b6944c088 Mon Sep 17 00:00:00 2001 From: Paulo Gustavo Veiga Date: Sun, 19 Aug 2012 11:10:38 -0300 Subject: [PATCH] Finally connection predict is working. --- mindplot/src/main/javascript/DragConnector.js | 36 ++++++++----------- mindplot/src/main/javascript/DragTopic.js | 2 +- 2 files changed, 16 insertions(+), 22 deletions(-) diff --git a/mindplot/src/main/javascript/DragConnector.js b/mindplot/src/main/javascript/DragConnector.js index 30861e7d..0b0da465 100644 --- a/mindplot/src/main/javascript/DragConnector.js +++ b/mindplot/src/main/javascript/DragConnector.js @@ -46,12 +46,18 @@ mindplot.DragConnector = new Class({ _searchConnectionCandidates:function (dragTopic) { var topics = this._designerModel.getTopics(); + var draggedNode = dragTopic.getDraggedTopic(); + + // Drag node connects to the border ... + var dragTopicWidth = dragTopic.getSize ? dragTopic.getSize().width : 0; // Hack... + var xMouseGap = dragTopic.getPosition().x > 0 ? 0 : dragTopicWidth; + var sPos = {x:dragTopic.getPosition().x - xMouseGap, y:dragTopic.getPosition().y}; + // Perform a initial filter to discard topics: // - Exclude dragged topic // - Exclude dragTopic pivot // - Nodes that are collapsed - var draggedNode = dragTopic.getDraggedTopic(); topics = topics.filter(function (topic) { return draggedNode != topic && topic != dragTopic._draggedNode && !topic.areChildrenShrunken() && !topic.isCollapsed(); }); @@ -59,41 +65,29 @@ mindplot.DragConnector = new Class({ // Filter all the nodes that are outside the vertical boundary: // * The node is to out of the x scope // * The x distance greater the vertical tolerated distance - var sourcePosition = dragTopic.getPosition(); topics = topics.filter(function (topic) { var tpos = topic.getPosition(); - var distance = (sourcePosition.x - tpos.x) * Math.sign(sourcePosition.x); - // Center topic has different alignment than the rest of the nodes. That's why i need to divide it by two... - var width = topic.getType() == mindplot.model.INodeModel.CENTRAL_TOPIC_TYPE ? topic.getSize().width / 2 : topic.getSize().width; - return (distance > width) && ((distance - width) < mindplot.DragConnector.MAX_VERTICAL_CONNECTION_TOLERANCE); + var txborder = tpos.x + (topic.getSize().width / 2) * Math.sign(sPos.x); + var distance = (sPos.x - txborder) * Math.sign(sPos.x); + return distance > 0 && (distance < mindplot.DragConnector.MAX_VERTICAL_CONNECTION_TOLERANCE); + }); // Assign a priority based on the distance: // - Alignment with the targetNode // - Vertical distance - // + // - Horizontal proximity topics = topics.sort(function (a, b) { var aPos = a.getPosition(); - var ad = (aPos.x - sourcePosition.x) * Math.sign(aPos.x); - var bPos = b.getPosition(); - var bd = ( bPos.x - sourcePosition.x) * Math.sign(bPos.x); - var av = this._isVerticallyAligned(a.getSize(), a.getPosition(), sourcePosition); - var bv = this._isVerticallyAligned(b.getSize(), b.getPosition(), sourcePosition); + var av = this._isVerticallyAligned(a.getSize(), a.getPosition(), sPos); + var bv = this._isVerticallyAligned(b.getSize(), b.getPosition(), sPos); - return ((bv ? 1000 : 1) + bd) - ((av ? 1000 : 1) + ad); + return ((av ? 1 : 10000) + Math.abs(aPos.x - sPos.x) + Math.abs(aPos.y - sPos.y)) - ((bv ? 1 : 10000) + Math.abs(bPos.x - sPos.x) + Math.abs(bPos.y - sPos.y)); }.bind(this)); - -// console.log("---- out ----"); -// topics.each(function (e) { -// console.log(e.getText()); -// }); -// console.log("---- out ----"); - - return topics; }, diff --git a/mindplot/src/main/javascript/DragTopic.js b/mindplot/src/main/javascript/DragTopic.js index 28c00e9b..e7415630 100644 --- a/mindplot/src/main/javascript/DragTopic.js +++ b/mindplot/src/main/javascript/DragTopic.js @@ -49,7 +49,7 @@ mindplot.DragTopic = new Class({ // All topic element must be positioned based on the innerShape. var draggedNode = this._draggedNode; var size = draggedNode.getSize(); - var cx = Math.ceil(position.x - (size.width / 2)); + var cx = position.x - (position.x > 0 ? 0 : size.width); var cy = Math.ceil(position.y - (size.height / 2)); this._elem2d.setPosition(cx, cy);