From ad98ccc8e0f8d2ec064d93c3c04d0f8beb44fd96 Mon Sep 17 00:00:00 2001 From: Pablo Luna Date: Fri, 6 May 2011 15:29:25 +0100 Subject: [PATCH] improving performance --- .../src/main/javascript/ConnectionLine.js | 3 ++- .../javascript/peer/svg/CurvedLinePeer.js | 20 ++++++++++++------- .../main/javascript/peer/svg/ElementPeer.js | 4 ++-- .../src/main/javascript/peer/svg/GroupPeer.js | 16 +++++++++++---- 4 files changed, 29 insertions(+), 14 deletions(-) diff --git a/mindplot/src/main/javascript/ConnectionLine.js b/mindplot/src/main/javascript/ConnectionLine.js index e9b0bb02..a44099fd 100644 --- a/mindplot/src/main/javascript/ConnectionLine.js +++ b/mindplot/src/main/javascript/ConnectionLine.js @@ -124,7 +124,7 @@ mindplot.ConnectionLine.prototype.redraw = function() line2d.setSrcControlPoint(ctrlPoints[0]); line2d.setDestControlPoint(ctrlPoints[1]); } - line2d.moveToBack(); +// line2d.moveToBack(); // Add connector ... this._positionateConnector(targetTopic); @@ -169,6 +169,7 @@ mindplot.ConnectionLine.prototype.setStroke = function(color, style, opacity) mindplot.ConnectionLine.prototype.addToWorkspace = function(workspace) { workspace.appendChild(this._line2d); + this._line2d.moveToBack(); }; mindplot.ConnectionLine.prototype.removeFromWorkspace = function(workspace) diff --git a/web2d/src/main/javascript/peer/svg/CurvedLinePeer.js b/web2d/src/main/javascript/peer/svg/CurvedLinePeer.js index 8c019b3b..958f5b73 100644 --- a/web2d/src/main/javascript/peer/svg/CurvedLinePeer.js +++ b/web2d/src/main/javascript/peer/svg/CurvedLinePeer.js @@ -33,22 +33,26 @@ objects.extend(web2d.peer.svg.CurvedLinePeer, web2d.peer.svg.ElementPeer); web2d.peer.svg.CurvedLinePeer.prototype.setSrcControlPoint = function(control){ this._customControlPoint_1 = true; + var change = this._control1.x!=control.x || this._control1.y!=control.y; if(core.Utils.isDefined(control.x)){ this._control1 = control; this._control1.x = parseInt(this._control1.x); this._control1.y = parseInt(this._control1.y) } - this._updatePath(); + if(change) + this._updatePath(); }; web2d.peer.svg.CurvedLinePeer.prototype.setDestControlPoint = function(control){ this._customControlPoint_2 = true; + var change = this._control2.x!=control.x || this._control2.y!=control.y; if(core.Utils.isDefined(control.x)){ this._control2 = control; this._control2.x = parseInt(this._control2.x); this._control2.y = parseInt(this._control2.y) } - this._updatePath(); + if(change) + this._updatePath(); }; web2d.peer.svg.CurvedLinePeer.prototype.isSrcControlPointCustom = function() { @@ -75,16 +79,20 @@ web2d.peer.svg.CurvedLinePeer.prototype.getControlPoints = function(){ web2d.peer.svg.CurvedLinePeer.prototype.setFrom = function(x1, y1) { + var change = this._x1!=parseInt(x1) || this._y1!=parseInt(y1); this._x1 = parseInt(x1); this._y1 = parseInt(y1); - this._updatePath(); + if(change) + this._updatePath(); }; web2d.peer.svg.CurvedLinePeer.prototype.setTo = function(x2, y2) { + var change = this._x2!=parseInt(x2) || this._y2!=parseInt(y2); this._x2 = parseInt(x2); this._y2 = parseInt(y2); - this._updatePath(); + if(change) + this._updatePath(); }; web2d.peer.svg.CurvedLinePeer.prototype.getFrom = function() @@ -152,7 +160,7 @@ web2d.peer.svg.CurvedLinePeer.prototype.isShowStartArrow = function(){ web2d.peer.svg.CurvedLinePeer.prototype._updatePath = function(avoidControlPointFix) { - if(core.Utils.isDefined(this._x1) && core.Utils.isDefined(this._y1)) + if(core.Utils.isDefined(this._x1) && core.Utils.isDefined(this._y1) && core.Utils.isDefined(this._x2) && core.Utils.isDefined(this._y2)) { this._calculateAutoControlPoints(avoidControlPointFix); var path = "M"+this._x1+","+this._y1 @@ -179,7 +187,6 @@ web2d.peer.svg.CurvedLinePeer.prototype._updateStyle = function() }; web2d.peer.svg.CurvedLinePeer.prototype._calculateAutoControlPoints = function(avoidControlPointFix){ - if(core.Utils.isDefined(this._x1) && core.Utils.isDefined(this._x2)){ //Both points available, calculate real points var defaultpoints = core.Utils.calculateDefaultControlPoints(new core.Point(this._x1, this._y1),new core.Point(this._x2,this._y2)); if(!this._customControlPoint_1 && !(core.Utils.isDefined(avoidControlPointFix) && avoidControlPointFix==0)){ @@ -190,7 +197,6 @@ web2d.peer.svg.CurvedLinePeer.prototype._calculateAutoControlPoints = function(a this._control2.x = defaultpoints[1].x; this._control2.y = defaultpoints[1].y; } - } }; web2d.peer.svg.CurvedLinePeer.prototype.setDashed = function(length,spacing){ diff --git a/web2d/src/main/javascript/peer/svg/ElementPeer.js b/web2d/src/main/javascript/peer/svg/ElementPeer.js index b60a4133..61ddb7b7 100644 --- a/web2d/src/main/javascript/peer/svg/ElementPeer.js +++ b/web2d/src/main/javascript/peer/svg/ElementPeer.js @@ -152,13 +152,13 @@ web2d.peer.svg.ElementPeer.prototype.removeEventListener = function(type, listen web2d.peer.svg.ElementPeer.prototype.setSize = function(width, height) { - if (core.Utils.isDefined(width)) + if (core.Utils.isDefined(width) && this._size.width != parseInt(width)) { this._size.width = parseInt(width); this._native.setAttribute('width', parseInt(width)); } - if (core.Utils.isDefined(height)) + if (core.Utils.isDefined(height) && this._size.height != parseInt(height)) { this._size.height = parseInt(height); this._native.setAttribute('height', parseInt(height)); diff --git a/web2d/src/main/javascript/peer/svg/GroupPeer.js b/web2d/src/main/javascript/peer/svg/GroupPeer.js index 08cc17d0..83148fdc 100644 --- a/web2d/src/main/javascript/peer/svg/GroupPeer.js +++ b/web2d/src/main/javascript/peer/svg/GroupPeer.js @@ -36,9 +36,11 @@ objects.extend(web2d.peer.svg.GroupPeer, web2d.peer.svg.ElementPeer); web2d.peer.svg.GroupPeer.prototype.setCoordSize = function(width, height) { + var change = this._coordSize.width!=width || this._coordSize.height!=height; this._coordSize.width = width; this._coordSize.height = height; - this.updateTransform(); + if(change) + this.updateTransform(); web2d.peer.utils.EventUtils.broadcastChangeEvent(this, "strokeStyle"); }; @@ -81,6 +83,7 @@ web2d.peer.svg.GroupPeer.prototype.updateTransform = function() web2d.peer.svg.GroupPeer.prototype.setCoordOrigin = function(x, y) { + var change = x!=this._coordOrigin.x || y!=this._coordOrigin.y; if (core.Utils.isDefined(x)) { this._coordOrigin.x = x; @@ -90,17 +93,21 @@ web2d.peer.svg.GroupPeer.prototype.setCoordOrigin = function(x, y) { this._coordOrigin.y = y; } - this.updateTransform(); + if(change) + this.updateTransform(); }; web2d.peer.svg.GroupPeer.prototype.setSize = function(width, height) { + var change = width != this._size.width || height!=this._size.height; web2d.peer.svg.GroupPeer.superClass.setSize.call(this, width, height); - this.updateTransform(); + if(change) + this.updateTransform(); }; web2d.peer.svg.GroupPeer.prototype.setPosition = function(x, y) { + var change = x!=this._position.x || y!=this._position.y; if (core.Utils.isDefined(x)) { this._position.x = parseInt(x); @@ -110,7 +117,8 @@ web2d.peer.svg.GroupPeer.prototype.setPosition = function(x, y) { this._position.y = parseInt(y); } - this.updateTransform(); + if(change) + this.updateTransform(); }; web2d.peer.svg.GroupPeer.prototype.getPosition = function()