diff --git a/mindplot/src/main/javascript/RelationshipPivot.js b/mindplot/src/main/javascript/RelationshipPivot.js index d8cbe769..e070e37f 100644 --- a/mindplot/src/main/javascript/RelationshipPivot.js +++ b/mindplot/src/main/javascript/RelationshipPivot.js @@ -43,7 +43,9 @@ mindplot.RelationshipPivot = new Class({ this._pivot = new web2d.CurvedLine(); this._pivot.setStyle(web2d.CurvedLine.SIMPLE_LINE); - this._pivot.setFrom(sourcePos.x, sourcePos.y); + + var fromPos = this._calculateFromPosition(sourcePos); + this._pivot.setFrom(fromPos.x, fromPos.y); this._pivot.setTo(targetPos.x, targetPos.y); this._pivot.setStroke(2, 'solid', strokeColor); @@ -54,7 +56,6 @@ mindplot.RelationshipPivot = new Class({ this._startArrow.setStrokeWidth(2); this._startArrow.setFrom(sourcePos.x, sourcePos.y); - this._workspace.appendChild(this._pivot); this._workspace.appendChild(this._startArrow); @@ -102,12 +103,7 @@ mindplot.RelationshipPivot = new Class({ var sourcePosition = this._sourceTopic.getPosition(); var gapDistance = Math.sign(pos.x - sourcePosition.x) * 5; - // Calculate origin position ... - var controPoint = mindplot.util.Shape.calculateDefaultControlPoints(sourcePosition, pos); - var spoint = new core.Point(); - spoint.x = parseInt(controPoint[0].x) + parseInt(sourcePosition.x); - spoint.y = parseInt(controPoint[0].y) + parseInt(sourcePosition.y); - var sPos = mindplot.util.Shape.calculateRelationShipPointCoordinates(this._sourceTopic, spoint); + var sPos = this._calculateFromPosition(pos); this._pivot.setFrom(sPos.x, sPos.y); // Update target position ... @@ -128,6 +124,21 @@ mindplot.RelationshipPivot = new Class({ event.stopPropagation(); }, + _calculateFromPosition:function (toPosition) { + + // Calculate origin position ... + var sourcePosition = this._sourceTopic.getPosition(); + if (this._sourceTopic.getType() == mindplot.model.INodeModel.CENTRAL_TOPIC_TYPE) { + sourcePosition = mindplot.util.Shape.workoutIncomingConnectionPoint(this._sourceTopic, toPosition); + } + var controlPoint = mindplot.util.Shape.calculateDefaultControlPoints(sourcePosition, toPosition); + + var spoint = new core.Point(); + spoint.x = parseInt(controlPoint[0].x) + parseInt(sourcePosition.x); + spoint.y = parseInt(controlPoint[0].y) + parseInt(sourcePosition.y); + return mindplot.util.Shape.calculateRelationShipPointCoordinates(this._sourceTopic, spoint); + }, + _connectOnFocus:function (targetTopic) { var sourceTopic = this._sourceTopic; var mindmap = this._designer.getMindmap(); diff --git a/mindplot/src/main/javascript/commands/DeleteCommand.js b/mindplot/src/main/javascript/commands/DeleteCommand.js index f160a19a..e1d47725 100644 --- a/mindplot/src/main/javascript/commands/DeleteCommand.js +++ b/mindplot/src/main/javascript/commands/DeleteCommand.js @@ -149,7 +149,18 @@ mindplot.commands.DeleteCommand = new Class({ return this._collectInDepthRelationships(topic); }, this); result.append(rels.flatten()); - return result; + + // Filter for unique ... + result = result.sort(function (a, b) { + return a.getModel().getId() - b.getModel().getId(); + }); + var ret = [result[0]]; + for (var i = 1; i < result.length; i++) { // start loop at 1 as element 0 can never be a duplicate + if (result[i - 1] !== result[i]) { + ret.push(result[i]); + } + } + return ret; } }); \ No newline at end of file diff --git a/mindplot/src/main/javascript/util/Shape.js b/mindplot/src/main/javascript/util/Shape.js index 121c4064..04d42e8e 100644 --- a/mindplot/src/main/javascript/util/Shape.js +++ b/mindplot/src/main/javascript/util/Shape.js @@ -46,15 +46,16 @@ mindplot.util.Shape = calculateRelationShipPointCoordinates:function (topic, controlPoint) { var size = topic.getSize(); var position = topic.getPosition(); - var div = (position.x - controlPoint.x); - div = (Math.abs(div) > 0.1 ? div : 0.1); // Prevent division by 0. + var m; + var yGap = position.y - controlPoint.y; + var xGap = position.x - controlPoint.x; + var disable = Math.abs(yGap) < 5 || Math.abs(xGap) < 5 || Math.abs(yGap - xGap) < 5; - var m = (position.y - controlPoint.y) / div; var y, x; var gap = 5; if (controlPoint.y > position.y + (size.height / 2)) { y = position.y + (size.height / 2) + gap; - x = position.x - ((position.y - y) / m); + x = !disable ? position.x - ((position.y - y) / (yGap / xGap)) : position.x; if (x > position.x + (size.width / 2)) { x = position.x + (size.width / 2); } else if (x < position.x - (size.width / 2)) { @@ -62,7 +63,7 @@ mindplot.util.Shape = } } else if (controlPoint.y < position.y - (size.height / 2)) { y = position.y - (size.height / 2) - gap; - x = position.x - ((position.y - y) / m); + x = !disable ? position.x - ((position.y - y) / (yGap / xGap)) : position.x; if (x > position.x + (size.width / 2)) { x = position.x + (size.width / 2); } else if (x < position.x - (size.width / 2)) { @@ -70,10 +71,10 @@ mindplot.util.Shape = } } else if (controlPoint.x < (position.x - size.width / 2)) { x = position.x - (size.width / 2) - gap; - y = position.y - (m * (position.x - x)); + y = !disable ? position.y - ((yGap / xGap) * (position.x - x)) : position.y; } else { x = position.x + (size.width / 2) + gap; - y = position.y - (m * (position.x - x)); + y = !disable ? position.y - ((yGap / xGap) * (position.x - x)) : position.y; } return new core.Point(x, y);