changing default shapes to be all lines, and fixing text centering bug

This commit is contained in:
Pablo Luna 2011-04-15 16:18:59 +01:00
parent 0f496bb4b3
commit d97121ce87
8 changed files with 39 additions and 58 deletions

View File

@ -39,7 +39,12 @@ mindplot.ConnectionLine = function(sourceNode, targetNode, lineType)
line.setStroke(1, 'solid', strokeColor); line.setStroke(1, 'solid', strokeColor);
} else } 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 = new web2d.PolyLine();
line.setStroke(1, 'solid', strokeColor); line.setStroke(1, 'solid', strokeColor);
} }
@ -48,14 +53,10 @@ mindplot.ConnectionLine = function(sourceNode, targetNode, lineType)
}; };
mindplot.ConnectionLine.prototype._getCtrlPoints = function(sourceNode, targetNode){ mindplot.ConnectionLine.prototype._getCtrlPoints = function(sourceNode, targetNode){
var srcPos = sourceNode.getPosition(); var srcPos = sourceNode.workoutOutgoingConnectionPoint(targetNode.getPosition());
var destPos = targetNode.getPosition(); var destPos = targetNode.workoutIncomingConnectionPoint(sourceNode.getPosition());
var deltaX = Math.abs(Math.abs(srcPos.x) - Math.abs(destPos.x))/3; var deltaX = (srcPos.x -destPos.x)/3;
var fix = 1; return [new core.Point(deltaX, 0), new core.Point(-deltaX, 0)];
if(mindplot.util.Shape.isAtRight(srcPos, destPos)){
fix=-1;
}
return [new core.Point(deltaX*fix, 0), new core.Point(deltaX*-fix, 0)];
}; };
mindplot.ConnectionLine.prototype._createLine = function(lineType, defaultStyle){ mindplot.ConnectionLine.prototype._createLine = function(lineType, defaultStyle){
@ -118,6 +119,11 @@ mindplot.ConnectionLine.prototype.redraw = function()
line2d.setFrom(tPos.x, tPos.y); line2d.setFrom(tPos.x, tPos.y);
line2d.setTo(sPos.x, sPos.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(); line2d.moveToBack();
// Add connector ... // Add connector ...

View File

@ -193,6 +193,6 @@ mindplot.IconGroup.prototype._calculateOffsets = function() {
var sizeHeight = text.getHtmlFontSize(); var sizeHeight = text.getHtmlFontSize();
var yOffset = offset; var yOffset = offset;
var shape = this.options.topic.getShapeType(); 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}; return {x:offset, y:yOffset};
}; };

View File

@ -110,23 +110,7 @@ mindplot.MainTopic.prototype._buildDragShape = function()
mindplot.MainTopic.prototype._defaultShapeType = function() mindplot.MainTopic.prototype._defaultShapeType = function()
{ {
var targetTopic = this.getOutgoingConnectedTopic(); return mindplot.NodeModel.SHAPE_TYPE_LINE;
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;
}; };
mindplot.MainTopic.prototype.updateTopicShape = function(targetTopic, workspace) mindplot.MainTopic.prototype.updateTopicShape = function(targetTopic, workspace)
@ -140,15 +124,8 @@ mindplot.MainTopic.prototype.updateTopicShape = function(targetTopic, workspace)
{ {
// Get the real shape type ... // Get the real shape type ...
shapeType = this.getShapeType(); shapeType = this.getShapeType();
this._setShapeType(mindplot.NodeModel.SHAPE_TYPE_LINE, false); this._setShapeType(shapeType, false);
}else if(shapeType==mindplot.NodeModel.SHAPE_TYPE_LINE){
var innerShape = this.getInnerShape();
innerShape.setVisibility(false);
} }
} else {
var innerShape = this.getInnerShape();
innerShape.setVisibility(true);
} }
this._helpers.forEach(function(helper){ this._helpers.forEach(function(helper){
helper.moveToFront(); helper.moveToFront();
@ -245,25 +222,25 @@ mindplot.MainTopic.prototype.workoutOutgoingConnectionPoint = function(targetPos
var result; var result;
if (this.getShapeType() == mindplot.NodeModel.SHAPE_TYPE_LINE) if (this.getShapeType() == mindplot.NodeModel.SHAPE_TYPE_LINE)
{ {
if (!this.isConnectedToCentralTopic()) // if (!this.isConnectedToCentralTopic())
{ // {
result = new core.Point(); result = new core.Point();
if (!isAtRight) if (!isAtRight)
{ {
result.x = pos.x - (size.width / 2); result.x = pos.x + (size.width / 2);
} else } else
{ {
result.x = pos.x + (size.width / 2); result.x = pos.x - (size.width / 2);
} }
result.y = pos.y + (size.height / 2); result.y = pos.y + (size.height / 2);
} else /*} else
{ {
// In this case, connetion line is not used as shape figure. // In this case, connetion line is not used as shape figure.
result = mindplot.util.Shape.calculateRectConnectionPoint(pos, size, isAtRight, true); result = mindplot.util.Shape.calculateRectConnectionPoint(pos, size, isAtRight, true);
result.y = pos.y + (size.height / 2); result.y = pos.y + (size.height / 2);
/*if(result.y>0){ *//*if(result.y>0){
result.y+=1; result.y+=1;
}*/ }*//*
// Correction factor ... // Correction factor ...
if (!isAtRight) if (!isAtRight)
@ -274,7 +251,7 @@ mindplot.MainTopic.prototype.workoutOutgoingConnectionPoint = function(targetPos
result.x = result.x - 2; result.x = result.x - 2;
} }
} }*/
} else } else
{ {
result = mindplot.util.Shape.calculateRectConnectionPoint(pos, size, isAtRight, true); result = mindplot.util.Shape.calculateRectConnectionPoint(pos, size, isAtRight, true);

View File

@ -238,8 +238,8 @@ mindplot.TextEditor.prototype.init = function (nodeGraph)
iconGroupSize = {width:0, height:0}; iconGroupSize = {width:0, height:0};
} }
var position = {x:0,y:0}; var position = {x:0,y:0};
position.x = pos.x - ((textWidth * scale.width) / 2) + ((iconGroupSize.width * scale.width)/2); position.x = pos.x - ((textWidth * scale.width) / 2) + (((iconGroupSize.width) * scale.width)/2);
var fixError = 4; var fixError =1;
position.y = pos.y - ((textHeight * scale.height) / 2) - fixError; position.y = pos.y - ((textHeight * scale.height) / 2) - fixError;
editor.setEditorSize(elemSize.width, elemSize.height, scale); editor.setEditorSize(elemSize.width, elemSize.height, scale);

View File

@ -86,11 +86,6 @@ mindplot.Topic.prototype._setShapeType = function(type, updateModel)
innerShape.addEventListener('mousedown', dispatcher._listeners[i]); 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 ... // Update figure size ...
var size = model.getSize(); var size = model.getSize();
@ -183,7 +178,7 @@ mindplot.Topic.prototype.buildShape = function(attributes, type)
} }
else if (type == mindplot.NodeModel.SHAPE_TYPE_LINE) 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) result.setSize = function(width, height)
{ {
this.size = {width:width, height:height}; this.size = {width:width, height:height};
@ -1360,8 +1355,8 @@ mindplot.Topic.prototype.updateNode = function(updatePosition)
var font = textShape.getFont(); var font = textShape.getFont();
var iconOffset = this.getIconOffset(); var iconOffset = this.getIconOffset();
var height = sizeHeight + this._offset; var height = sizeHeight + this._offset;
var width = sizeWidth + this._offset*2 + iconOffset; var width = sizeWidth + this._offset*2 + iconOffset +2;
var pos = this._offset /2; var pos = this._offset /2 -1;
if(this.getShapeType()==mindplot.NodeModel.SHAPE_TYPE_ELIPSE){ if(this.getShapeType()==mindplot.NodeModel.SHAPE_TYPE_ELIPSE){
var factor = 0.25; var factor = 0.25;
height = (width*factor<height?height:width*factor); height = (width*factor<height?height:width*factor);
@ -1372,7 +1367,7 @@ mindplot.Topic.prototype.updateNode = function(updatePosition)
this.setSize(newSize, false, updatePosition); this.setSize(newSize, false, updatePosition);
// Positionate node ... // Positionate node ...
textShape.setPosition(iconOffset+this._offset, pos); textShape.setPosition(iconOffset+this._offset+2, pos);
textShape.setTextSize(sizeWidth, sizeHeight); textShape.setTextSize(sizeWidth, sizeHeight);
var iconGroup = this.getIconGroup(); var iconGroup = this.getIconGroup();
if(core.Utils.isDefined(iconGroup)) if(core.Utils.isDefined(iconGroup))

View File

@ -22,7 +22,7 @@ mindplot.util.Shape =
{ {
core.assert(sourcePoint, "Source can not be null"); core.assert(sourcePoint, "Source can not be null");
core.assert(targetPoint, "Target can not be null"); core.assert(targetPoint, "Target can not be null");
return (targetPoint.x - sourcePoint.x) > 0; return sourcePoint.x < targetPoint.x;
}, },
workoutDistance: function(sourceNode, targetNode) workoutDistance: function(sourceNode, targetNode)
{ {

View File

@ -19,7 +19,7 @@
web2d.Line = function(attributes) web2d.Line = function(attributes)
{ {
var peer = web2d.peer.Toolkit.createLine(); 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) for (var key in attributes)
{ {
defaultAttributes[key] = attributes[key]; defaultAttributes[key] = attributes[key];

View File

@ -62,8 +62,11 @@ web2d.peer.svg.TextPeer.prototype.getText = function()
web2d.peer.svg.TextPeer.prototype.setPosition = function(x, y) web2d.peer.svg.TextPeer.prototype.setPosition = function(x, y)
{ {
this._position = {x:x, y:y}; this._position = {x:x, y:y};
var size = parseInt(this._font.getSize()); var height = this._font.getSize();
this._native.setAttribute('y', y + size); if(this._parent && this._native.getBBox)
height = this.getHeight();
var size = parseInt(height);
this._native.setAttribute('y', y+size*3/4);
//y+size/2 //y+size/2
this._native.setAttribute('x', x); this._native.setAttribute('x', x);
}; };