fixing node dragging

This commit is contained in:
Pablo Luna 2011-06-14 16:59:13 +01:00
parent 8ce317e71f
commit 5a93c1f0d5
3 changed files with 25 additions and 7 deletions

View File

@ -36,7 +36,8 @@ mindplot.DragPivot.prototype.getTargetTopic = function()
mindplot.DragPivot.prototype._buildStraightLine = function() mindplot.DragPivot.prototype._buildStraightLine = function()
{ {
var line = new web2d.Line(); var line = new web2d.CurvedLine();
line.setStyle(web2d.CurvedLine.SIMPLE_LINE);
line.setStroke(1, 'solid', '#CC0033'); line.setStroke(1, 'solid', '#CC0033');
line.setOpacity(0.4); line.setOpacity(0.4);
line.setVisibility(false); line.setVisibility(false);
@ -45,7 +46,8 @@ mindplot.DragPivot.prototype._buildStraightLine = function()
mindplot.DragPivot.prototype._buildCurvedLine = function() mindplot.DragPivot.prototype._buildCurvedLine = function()
{ {
var line = new web2d.PolyLine(); var line = new web2d.CurvedLine();
line.setStyle(web2d.CurvedLine.SIMPLE_LINE);
line.setStroke(1, 'solid', '#CC0033'); line.setStroke(1, 'solid', '#CC0033');
line.setOpacity(0.4); line.setOpacity(0.4);
line.setVisibility(false); line.setVisibility(false);

View File

@ -42,7 +42,7 @@ mindplot.DragTopicPositioner.prototype.positionateDragTopic = function(dragTopic
} }
}; };
mindplot.DragTopicPositioner.CENTRAL_TO_MAINTOPIC_MAX_HORIZONTAL_DISTANCE = 300; mindplot.DragTopicPositioner.CENTRAL_TO_MAINTOPIC_MAX_HORIZONTAL_DISTANCE = 400;
mindplot.DragTopicPositioner.prototype._checkDragTopicConnection = function(dragTopic) mindplot.DragTopicPositioner.prototype._checkDragTopicConnection = function(dragTopic)
{ {
@ -99,6 +99,7 @@ mindplot.DragTopicPositioner.prototype._lookUpForMainTopicToMainTopicConnection
var result = null; var result = null;
var clouserDistance = -1; var clouserDistance = -1;
var draggedNode = dragTopic.getDraggedTopic(); var draggedNode = dragTopic.getDraggedTopic();
var distance = null;
// Check MainTopic->MainTopic connection... // Check MainTopic->MainTopic connection...
for (var i = 0; i < topics.length; i++) for (var i = 0; i < topics.length; i++)
@ -110,8 +111,19 @@ mindplot.DragTopicPositioner.prototype._lookUpForMainTopicToMainTopicConnection
var canBeConnected = dragTopic.canBeConnectedTo(targetTopic); var canBeConnected = dragTopic.canBeConnectedTo(targetTopic);
if (canBeConnected) if (canBeConnected)
{ {
result = targetTopic; var targetPosition = targetTopic.getPosition();
break; var fix = position.y>targetPosition.y;
var gap = 0;
if(targetTopic._getChildren().length>0){
gap = Math.abs(targetPosition.y - targetTopic._getChildren()[0].getPosition().y)
}
var yDistance = Math.abs(position.y -fix*gap - targetPosition.y);
if(distance==null || yDistance<distance)
{
result = targetTopic;
distance = yDistance;
}
} }
} }
} }

View File

@ -305,8 +305,12 @@ mindplot.NodeModel.prototype.canBeConnected = function(sourceModel, sourcePositi
// Finally, check current node ubication. // Finally, check current node ubication.
var targetTopicSize = targetModel.getSize(); var targetTopicSize = targetModel.getSize();
var yDistance = Math.abs(sourcePosition.y - targetPosition.y); var yDistance = Math.abs(sourcePosition.y - targetPosition.y);
var gap = 35 + targetTopicHeight / 2;
if(targetModel.getChildren().length>0){
gap += Math.abs(targetPosition.y - targetModel.getChildren()[0].getPosition().y);
}
if (yDistance <= 5 + targetTopicHeight / 2) if (yDistance <= gap)
{ {
// Circular connection ? // Circular connection ?
if (!sourceModel._isChildNode(this)) if (!sourceModel._isChildNode(this))
@ -339,7 +343,7 @@ mindplot.NodeModel.prototype.canBeConnected = function(sourceModel, sourcePositi
return result; return result;
}; };
mindplot.NodeModel.MAIN_TOPIC_TO_MAIN_TOPIC_DISTANCE = 60; mindplot.NodeModel.MAIN_TOPIC_TO_MAIN_TOPIC_DISTANCE = 220;
mindplot.NodeModel.prototype._isChildNode = function(node) mindplot.NodeModel.prototype._isChildNode = function(node)
{ {