From d97121ce87c2a9250571bbdd767872e6f6431fec Mon Sep 17 00:00:00 2001 From: Pablo Luna Date: Fri, 15 Apr 2011 16:18:59 +0100 Subject: [PATCH] changing default shapes to be all lines, and fixing text centering bug --- .../src/main/javascript/ConnectionLine.js | 24 +++++++---- mindplot/src/main/javascript/IconGroup.js | 2 +- mindplot/src/main/javascript/MainTopic.js | 43 +++++-------------- mindplot/src/main/javascript/TextEditor.js | 4 +- mindplot/src/main/javascript/Topic.js | 13 ++---- mindplot/src/main/javascript/util/Shape.js | 2 +- web2d/src/main/javascript/Line.js | 2 +- .../src/main/javascript/peer/svg/TextPeer.js | 7 ++- 8 files changed, 39 insertions(+), 58 deletions(-) diff --git a/mindplot/src/main/javascript/ConnectionLine.js b/mindplot/src/main/javascript/ConnectionLine.js index ce94b41a..9af953b2 100644 --- a/mindplot/src/main/javascript/ConnectionLine.js +++ b/mindplot/src/main/javascript/ConnectionLine.js @@ -39,7 +39,12 @@ mindplot.ConnectionLine = function(sourceNode, targetNode, lineType) line.setStroke(1, 'solid', strokeColor); } else { - line = this._createLine(lineType,mindplot.ConnectionLine.POLYLINE); + line = this._createLine(lineType,mindplot.ConnectionLine.SIMPLE_CURVED); + if(line.getType()=="CurvedLine"){ + var ctrlPoints = this._getCtrlPoints(sourceNode, targetNode); + line.setSrcControlPoint(ctrlPoints[0]); + line.setDestControlPoint(ctrlPoints[1]); + } // line = new web2d.PolyLine(); line.setStroke(1, 'solid', strokeColor); } @@ -48,14 +53,10 @@ mindplot.ConnectionLine = function(sourceNode, targetNode, lineType) }; mindplot.ConnectionLine.prototype._getCtrlPoints = function(sourceNode, targetNode){ - var srcPos = sourceNode.getPosition(); - var destPos = targetNode.getPosition(); - var deltaX = Math.abs(Math.abs(srcPos.x) - Math.abs(destPos.x))/3; - var fix = 1; - if(mindplot.util.Shape.isAtRight(srcPos, destPos)){ - fix=-1; - } - return [new core.Point(deltaX*fix, 0), new core.Point(deltaX*-fix, 0)]; + var srcPos = sourceNode.workoutOutgoingConnectionPoint(targetNode.getPosition()); + var destPos = targetNode.workoutIncomingConnectionPoint(sourceNode.getPosition()); + var deltaX = (srcPos.x -destPos.x)/3; + return [new core.Point(deltaX, 0), new core.Point(-deltaX, 0)]; }; mindplot.ConnectionLine.prototype._createLine = function(lineType, defaultStyle){ @@ -118,6 +119,11 @@ mindplot.ConnectionLine.prototype.redraw = function() line2d.setFrom(tPos.x, tPos.y); line2d.setTo(sPos.x, sPos.y); + if(line2d.getType()=="CurvedLine"){ + var ctrlPoints = this._getCtrlPoints(this._sourceTopic, this._targetTopic); + line2d.setSrcControlPoint(ctrlPoints[0]); + line2d.setDestControlPoint(ctrlPoints[1]); + } line2d.moveToBack(); // Add connector ... diff --git a/mindplot/src/main/javascript/IconGroup.js b/mindplot/src/main/javascript/IconGroup.js index ff96397a..fdb1ee29 100644 --- a/mindplot/src/main/javascript/IconGroup.js +++ b/mindplot/src/main/javascript/IconGroup.js @@ -193,6 +193,6 @@ mindplot.IconGroup.prototype._calculateOffsets = function() { var sizeHeight = text.getHtmlFontSize(); var yOffset = offset; var shape = this.options.topic.getShapeType(); - yOffset = text.getPosition().y + (sizeHeight - 18)/2; + yOffset = text.getPosition().y + (sizeHeight - 18)/2 + 1; return {x:offset, y:yOffset}; }; \ No newline at end of file diff --git a/mindplot/src/main/javascript/MainTopic.js b/mindplot/src/main/javascript/MainTopic.js index df198905..e07bea1c 100644 --- a/mindplot/src/main/javascript/MainTopic.js +++ b/mindplot/src/main/javascript/MainTopic.js @@ -110,23 +110,7 @@ mindplot.MainTopic.prototype._buildDragShape = function() mindplot.MainTopic.prototype._defaultShapeType = function() { - var targetTopic = this.getOutgoingConnectedTopic(); - var result; - if (targetTopic) - { - if (targetTopic.getType() != mindplot.NodeModel.CENTRAL_TOPIC_TYPE) - { - result = mindplot.NodeModel.SHAPE_TYPE_LINE; - - } else - { - result = mindplot.NodeModel.SHAPE_TYPE_ROUNDED_RECT; - } - } else - { - result = mindplot.NodeModel.SHAPE_TYPE_ROUNDED_RECT; - } - return result; + return mindplot.NodeModel.SHAPE_TYPE_LINE; }; mindplot.MainTopic.prototype.updateTopicShape = function(targetTopic, workspace) @@ -140,15 +124,8 @@ mindplot.MainTopic.prototype.updateTopicShape = function(targetTopic, workspace) { // Get the real shape type ... shapeType = this.getShapeType(); - this._setShapeType(mindplot.NodeModel.SHAPE_TYPE_LINE, false); - }else if(shapeType==mindplot.NodeModel.SHAPE_TYPE_LINE){ - var innerShape = this.getInnerShape(); - innerShape.setVisibility(false); - + this._setShapeType(shapeType, false); } - } else { - var innerShape = this.getInnerShape(); - innerShape.setVisibility(true); } this._helpers.forEach(function(helper){ helper.moveToFront(); @@ -245,25 +222,25 @@ mindplot.MainTopic.prototype.workoutOutgoingConnectionPoint = function(targetPos var result; if (this.getShapeType() == mindplot.NodeModel.SHAPE_TYPE_LINE) { - if (!this.isConnectedToCentralTopic()) - { +// if (!this.isConnectedToCentralTopic()) +// { result = new core.Point(); if (!isAtRight) { - result.x = pos.x - (size.width / 2); + result.x = pos.x + (size.width / 2); } else { - result.x = pos.x + (size.width / 2); + result.x = pos.x - (size.width / 2); } result.y = pos.y + (size.height / 2); - } else + /*} else { // In this case, connetion line is not used as shape figure. result = mindplot.util.Shape.calculateRectConnectionPoint(pos, size, isAtRight, true); result.y = pos.y + (size.height / 2); - /*if(result.y>0){ + *//*if(result.y>0){ result.y+=1; - }*/ + }*//* // Correction factor ... if (!isAtRight) @@ -274,7 +251,7 @@ mindplot.MainTopic.prototype.workoutOutgoingConnectionPoint = function(targetPos result.x = result.x - 2; } - } + }*/ } else { result = mindplot.util.Shape.calculateRectConnectionPoint(pos, size, isAtRight, true); diff --git a/mindplot/src/main/javascript/TextEditor.js b/mindplot/src/main/javascript/TextEditor.js index c3e6b401..7d32d9b4 100644 --- a/mindplot/src/main/javascript/TextEditor.js +++ b/mindplot/src/main/javascript/TextEditor.js @@ -238,8 +238,8 @@ mindplot.TextEditor.prototype.init = function (nodeGraph) iconGroupSize = {width:0, height:0}; } var position = {x:0,y:0}; - position.x = pos.x - ((textWidth * scale.width) / 2) + ((iconGroupSize.width * scale.width)/2); - var fixError = 4; + position.x = pos.x - ((textWidth * scale.width) / 2) + (((iconGroupSize.width) * scale.width)/2); + var fixError =1; position.y = pos.y - ((textHeight * scale.height) / 2) - fixError; editor.setEditorSize(elemSize.width, elemSize.height, scale); diff --git a/mindplot/src/main/javascript/Topic.js b/mindplot/src/main/javascript/Topic.js index d79b8a98..b26782c1 100644 --- a/mindplot/src/main/javascript/Topic.js +++ b/mindplot/src/main/javascript/Topic.js @@ -86,11 +86,6 @@ mindplot.Topic.prototype._setShapeType = function(type, updateModel) innerShape.addEventListener('mousedown', dispatcher._listeners[i]); } } - if (!this.isConnectedToCentralTopic() && type == mindplot.NodeModel.SHAPE_TYPE_LINE) - { - // In this case, The normal connection line is not used. - innerShape.setVisibility(false); - } // Update figure size ... var size = model.getSize(); @@ -183,7 +178,7 @@ mindplot.Topic.prototype.buildShape = function(attributes, type) } else if (type == mindplot.NodeModel.SHAPE_TYPE_LINE) { - result = new web2d.Line(); + result = new web2d.Line({strokeWidth:1, strokeOpacity:1}); result.setSize = function(width, height) { this.size = {width:width, height:height}; @@ -1360,8 +1355,8 @@ mindplot.Topic.prototype.updateNode = function(updatePosition) var font = textShape.getFont(); var iconOffset = this.getIconOffset(); var height = sizeHeight + this._offset; - var width = sizeWidth + this._offset*2 + iconOffset; - var pos = this._offset /2; + var width = sizeWidth + this._offset*2 + iconOffset +2; + var pos = this._offset /2 -1; if(this.getShapeType()==mindplot.NodeModel.SHAPE_TYPE_ELIPSE){ var factor = 0.25; height = (width*factor 0; + return sourcePoint.x < targetPoint.x; }, workoutDistance: function(sourceNode, targetNode) { diff --git a/web2d/src/main/javascript/Line.js b/web2d/src/main/javascript/Line.js index 6aa2e456..9d9d36d7 100644 --- a/web2d/src/main/javascript/Line.js +++ b/web2d/src/main/javascript/Line.js @@ -19,7 +19,7 @@ web2d.Line = function(attributes) { var peer = web2d.peer.Toolkit.createLine(); - var defaultAttributes = {strokeColor:'#495879',strokeWidth:1}; + var defaultAttributes = {strokeColor:'#495879',strokeWidth:1, strokeOpacity:1}; for (var key in attributes) { defaultAttributes[key] = attributes[key]; diff --git a/web2d/src/main/javascript/peer/svg/TextPeer.js b/web2d/src/main/javascript/peer/svg/TextPeer.js index 67d6f789..4dbea947 100644 --- a/web2d/src/main/javascript/peer/svg/TextPeer.js +++ b/web2d/src/main/javascript/peer/svg/TextPeer.js @@ -62,8 +62,11 @@ web2d.peer.svg.TextPeer.prototype.getText = function() web2d.peer.svg.TextPeer.prototype.setPosition = function(x, y) { this._position = {x:x, y:y}; - var size = parseInt(this._font.getSize()); - this._native.setAttribute('y', y + size); + var height = this._font.getSize(); + if(this._parent && this._native.getBBox) + height = this.getHeight(); + var size = parseInt(height); + this._native.setAttribute('y', y+size*3/4); //y+size/2 this._native.setAttribute('x', x); };