mirror of
https://bitbucket.org/wisemapping/wisemapping-open-source.git
synced 2024-11-22 22:27:55 +01:00
First clean up of the algorithm.
This commit is contained in:
parent
c432bef6b1
commit
bff79159e1
@ -47,8 +47,7 @@ mindplot.DragConnector = new Class({
|
||||
if ($defined(mainTopicToMainTopicConnection)) {
|
||||
// I have to change the current connection to a main topic.
|
||||
dragTopic.disconnect(this._workspace);
|
||||
} else
|
||||
if (Math.abs(dragXPosition - currentXPosition) > mindplot.DragConnector.CENTRAL_TO_MAINTOPIC_MAX_HORIZONTAL_DISTANCE) {
|
||||
} else if (Math.abs(dragXPosition - currentXPosition) > mindplot.DragConnector.CENTRAL_TO_MAINTOPIC_MAX_HORIZONTAL_DISTANCE) {
|
||||
dragTopic.disconnect(this._workspace);
|
||||
}
|
||||
}
|
||||
@ -67,15 +66,34 @@ mindplot.DragConnector = new Class({
|
||||
|
||||
_lookUpForMainTopicToMainTopicConnection:function (dragTopic) {
|
||||
var topics = this._designerModel.getTopics();
|
||||
var result = null;
|
||||
|
||||
// Filter all the nodes that are outside the boundary ...
|
||||
var draggedNode = dragTopic.getDraggedTopic();
|
||||
var distance = null;
|
||||
var sourcePosition = dragTopic.getPosition();
|
||||
topics = topics.filter(function (topic) {
|
||||
var pos = topic.getPosition();
|
||||
return (sourcePosition.x - pos.x) * Math.sign(pos.x) > 0 && draggedNode != topic;
|
||||
});
|
||||
|
||||
// Topics must be ordered based on the distance vertical distance to the drag topic ...
|
||||
topics = topics.sort(function (a, b) {
|
||||
var aPos = a.getPosition();
|
||||
var ad = (sourcePosition.x - aPos.x) * Math.sign(aPos.x);
|
||||
|
||||
var bPos = b.getPosition();
|
||||
var bd = (sourcePosition.x - bPos.x) * Math.sign(bPos.x);
|
||||
|
||||
return ad > bd;
|
||||
});
|
||||
|
||||
|
||||
// Check MainTopic->MainTopic connection...
|
||||
var result = null;
|
||||
var distance = null;
|
||||
for (var i = 0; i < topics.length; i++) {
|
||||
var targetTopic = topics[i];
|
||||
var position = dragTopic.getPosition();
|
||||
if (targetTopic.getType() != mindplot.model.INodeModel.CENTRAL_TOPIC_TYPE && targetTopic != draggedNode) {
|
||||
var targetTopic = topics[i];
|
||||
|
||||
var canBeConnected = dragTopic.canBeConnectedTo(targetTopic);
|
||||
if (canBeConnected) {
|
||||
var targetPosition = targetTopic.getPosition();
|
||||
@ -84,12 +102,12 @@ mindplot.DragConnector = new Class({
|
||||
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;
|
||||
}
|
||||
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -110,7 +110,7 @@ mindplot.DragTopic = new Class({
|
||||
var targetTopicModel = targetTopic.getModel();
|
||||
var childTopicModel = draggedNode.getModel();
|
||||
|
||||
result = targetTopicModel.canBeConnected(childTopicModel, topicPosition, 18, targetTopic.getSize());
|
||||
result = targetTopicModel.canBeConnected(childTopicModel, topicPosition, targetTopic.getSize());
|
||||
}
|
||||
} else {
|
||||
result = false;
|
||||
|
@ -142,50 +142,30 @@ mindplot.model.NodeModel = new Class({
|
||||
this._parent = parent;
|
||||
},
|
||||
|
||||
canBeConnected:function (sourceModel, sourcePosition, targetTopicHeight, targetTopicSize) {
|
||||
canBeConnected:function (sourceModel, sourcePosition, targetTopicSize) {
|
||||
|
||||
$assert(sourceModel != this, 'The same node can not be parent and child if itself.');
|
||||
$assert(sourcePosition, 'childPosition can not be null.');
|
||||
$assert(targetTopicHeight, 'childrenWidth can not be null.');
|
||||
$assert(targetTopicSize, 'targetTopicSize can not be null.');
|
||||
|
||||
|
||||
// Only can be connected if the node is in the left or rigth.
|
||||
var targetModel = this;
|
||||
var mindmap = targetModel.getMindmap();
|
||||
var targetPosition = targetModel.getPosition();
|
||||
var result = false;
|
||||
|
||||
if (sourceModel.getType() == mindplot.model.INodeModel.MAIN_TOPIC_TYPE) {
|
||||
// Only can be connected if the node is in the left or right.
|
||||
var targetModel = this;
|
||||
var targetPosition = targetModel.getPosition();
|
||||
|
||||
// Finally, check current node position ...
|
||||
var yDistance = Math.abs(sourcePosition.y - targetPosition.y);
|
||||
var gap = 35 + targetTopicHeight / 2;
|
||||
var gap = 35 + targetTopicSize.height / 2;
|
||||
if (targetModel.getChildren().length > 0) {
|
||||
gap += Math.abs(targetPosition.y - targetModel.getChildren()[0].getPosition().y);
|
||||
}
|
||||
|
||||
if (yDistance <= gap) {
|
||||
// Circular connection ?
|
||||
if (!sourceModel._isChildNode(this)) {
|
||||
var toleranceDistance = (targetTopicSize.width / 2) + targetTopicHeight;
|
||||
|
||||
var xDistance = sourcePosition.x - targetPosition.x;
|
||||
var isTargetAtRightFromCentral = targetPosition.x >= 0;
|
||||
|
||||
if (isTargetAtRightFromCentral) {
|
||||
if (xDistance >= -targetTopicSize.width / 2 && xDistance <= mindplot.model.INodeModel.MAIN_TOPIC_TO_MAIN_TOPIC_DISTANCE / 2 + (targetTopicSize.width / 2)) {
|
||||
result = true;
|
||||
var xDistance = (sourcePosition.x - targetPosition.x) * Math.sign(targetPosition.x);
|
||||
result = xDistance > targetTopicSize.width;
|
||||
}
|
||||
|
||||
} else {
|
||||
if (xDistance <= targetTopicSize.width / 2 && Math.abs(xDistance) <= mindplot.model.INodeModel.MAIN_TOPIC_TO_MAIN_TOPIC_DISTANCE / 2 + (targetTopicSize.width / 2)) {
|
||||
result = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
} else {
|
||||
throw "No implemented yet";
|
||||
}
|
||||
return result;
|
||||
},
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user