Fix relationship central node positioning problem ...

This commit is contained in:
Paulo Gustavo Veiga 2012-11-17 12:02:59 -03:00
parent f8a6607de9
commit fc6d91f59e
4 changed files with 36 additions and 30 deletions

View File

@ -29,17 +29,13 @@ mindplot.ConnectionLine = new Class({
var ctrlPoints = this._getCtrlPoints(sourceNode, targetNode);
if (targetNode.getType() == mindplot.model.INodeModel.CENTRAL_TOPIC_TYPE) {
line = this._createLine(lineType, mindplot.ConnectionLine.CURVED);
if (line.getType() == "CurvedLine") {
line.setSrcControlPoint(ctrlPoints[0]);
line.setDestControlPoint(ctrlPoints[1]);
}
} else {
line = this._createLine(lineType, mindplot.ConnectionLine.SIMPLE_CURVED);
if (line.getType() == "CurvedLine") {
line.setSrcControlPoint(ctrlPoints[0]);
line.setDestControlPoint(ctrlPoints[1]);
}
}
// Set line styles ...
var strokeColor = mindplot.ConnectionLine.getStrokeColor();
line.setStroke(1, 'solid', strokeColor, 1);

View File

@ -98,28 +98,7 @@ mindplot.MainTopic = new Class({
},
workoutIncomingConnectionPoint:function (sourcePosition) {
$assert(sourcePosition, 'sourcePoint can not be null');
var pos = this.getPosition();
var size = this.getSize();
var isAtRight = mindplot.util.Shape.isAtRight(sourcePosition, pos);
var result = mindplot.util.Shape.calculateRectConnectionPoint(pos, size, isAtRight);
if (this.getShapeType() == mindplot.model.TopicShape.LINE) {
result.y = result.y + (this.getSize().height / 2);
}
// Move a little the position...
var offset = mindplot.Topic.CONNECTOR_WIDTH / 2;
if (this.getPosition().x > 0) {
result.x = result.x + offset;
} else {
result.x = result.x - offset;
}
result.x = Math.ceil(result.x);
result.y = Math.ceil(result.y);
return result;
return mindplot.util.Shape.workoutIncomingConnectionPoint(this, sourcePosition);
},
workoutOutgoingConnectionPoint:function (targetPosition) {

View File

@ -83,14 +83,19 @@ mindplot.Relationship = new Class({
var targetTopic = this._targetTopic;
var targetPosition = targetTopic.getPosition();
if (targetTopic.getType() == mindplot.model.INodeModel.CENTRAL_TOPIC_TYPE) {
targetPosition = mindplot.util.Shape.workoutIncomingConnectionPoint(targetTopic, sourcePosition);
}
var sPos, tPos;
this._line2d.setStroke(2);
var ctrlPoints = this._line2d.getControlPoints();
if (!this._line2d.isDestControlPointCustom() && !this._line2d.isSrcControlPointCustom()) {
var defaultPoints = mindplot.util.Shape.calculateDefaultControlPoints(sourcePosition, targetPosition);
ctrlPoints[0].x = defaultPoints[0].x;
ctrlPoints[0].y = defaultPoints[0].y;
ctrlPoints[1].x = defaultPoints[1].x;
ctrlPoints[1].y = defaultPoints[1].y;
}
@ -101,6 +106,7 @@ mindplot.Relationship = new Class({
var tpoint = new core.Point();
tpoint.x = parseInt(ctrlPoints[1].x) + parseInt(targetPosition.x);
tpoint.y = parseInt(ctrlPoints[1].y) + parseInt(targetPosition.y);
sPos = mindplot.util.Shape.calculateRelationShipPointCoordinates(sourceTopic, spoint);
tPos = mindplot.util.Shape.calculateRelationShipPointCoordinates(targetTopic, tpoint);

View File

@ -97,6 +97,31 @@ mindplot.util.Shape =
var y2 = m * (x2 - tarPos.x) + tarPos.y;
return [new core.Point(-srcPos.x + x1, -srcPos.y + y1), new core.Point(-tarPos.x + x2, -tarPos.y + y2)];
},
workoutIncomingConnectionPoint:function (targetNode, sourcePosition) {
$assert(sourcePosition, 'sourcePoint can not be null');
var pos = targetNode.getPosition();
var size = targetNode.getSize();
var isAtRight = mindplot.util.Shape.isAtRight(sourcePosition, pos);
var result = mindplot.util.Shape.calculateRectConnectionPoint(pos, size, isAtRight);
if (targetNode.getShapeType() == mindplot.model.TopicShape.LINE) {
result.y = result.y + (targetNode.getSize().height / 2);
}
// Move a little the position...
var offset = mindplot.Topic.CONNECTOR_WIDTH / 2;
if (!isAtRight) {
result.x = result.x + offset;
} else {
result.x = result.x - offset;
}
result.x = Math.ceil(result.x);
result.y = Math.ceil(result.y);
return result;
}
};