refresh tree update -- much better

This commit is contained in:
Peter Cottle 2012-09-22 23:19:40 -07:00
parent 04251a3da3
commit 24c344a4d0
2 changed files with 27 additions and 22 deletions

View file

@ -28,12 +28,9 @@ var VisBranch = Backbone.Model.extend({
genGraphics: function(paper) {
var pos = this.getPosition();
if (!paper) {
console.log('no paper');
return;
}
var name = this.get('branch').get('id');
var text = paper.text(pos.x, pos.y, String(name));
text.attr({
'font-size': 16
});
@ -46,7 +43,8 @@ var VisBranch = Backbone.Model.extend({
x: pos.x,
y: pos.y
},
speed || this.get('animationSpeed'),
// speed can be 0 when we want a harsh animation
speed !== undefined ? speed : this.get('animationSpeed'),
easing || this.get('animationEasing')
);
}
@ -100,7 +98,7 @@ var VisNode = Backbone.Model.extend({
cx: pos.x,
cy: pos.y
},
speed || this.get('animationSpeed'),
speed !== undefined ? speed : this.get('animationSpeed'),
easing || this.get('animationEasing')
);
},
@ -210,7 +208,7 @@ var VisEdge = Backbone.Model.extend({
this.get('path').stop().animate({
path: newPath
},
speed || this.get('animationSpeed'),
speed !== undefined ? speed : this.get('animationSpeed'),
easing || this.get('animationEasing')
);
},

View file

@ -71,19 +71,21 @@ GitVisuals.prototype.toScreenCoords = function(pos) {
**************************************/
GitVisuals.prototype.refreshTree = function() {
if (!this.paperReady) { console.warn('called refresh tree when not ready yet'); return; }
this.calculateTreeCoords();
this.animateNodePositions();
this.animateEdges();
this.animateRefs();
this.animateAll();
};
GitVisuals.prototype.refreshTreeHarsh = function() {
this.calculateTreeCoords();
this.animateEdges();
this.animateNodePositions();
this.animateAll(0);
};
GitVisuals.prototype.animateAll = function(speed) {
this.animateEdges(speed);
this.animateNodePositions(speed);
this.animateRefs(speed);
};
GitVisuals.prototype.calculateTreeCoords = function() {
@ -180,9 +182,9 @@ GitVisuals.prototype.calcDepth = function() {
**************************************/
GitVisuals.prototype.animateNodePositions = function() {
GitVisuals.prototype.animateNodePositions = function(speed) {
_.each(this.visNodeMap, function(visNode) {
visNode.animateUpdatedPosition();
visNode.animateUpdatedPosition(speed);
}, this);
};
@ -196,15 +198,15 @@ GitVisuals.prototype.addBranch = function(branch) {
}
};
GitVisuals.prototype.animateRefs = function() {
GitVisuals.prototype.animateRefs = function(speed) {
this.visBranchCollection.each(function(visBranch) {
visBranch.animateUpdatedPos(paper);
visBranch.animateUpdatedPos(speed);
}, this);
};
GitVisuals.prototype.animateEdges = function() {
GitVisuals.prototype.animateEdges = function(speed) {
this.edgeCollection.each(function(edge) {
edge.animateUpdatedPath();
edge.animateUpdatedPath(speed);
}, this);
};
@ -232,7 +234,12 @@ GitVisuals.prototype.calcDepthRecursive = function(commit, depth) {
GitVisuals.prototype.canvasResize = function(width, height) {
this.paperWidth = width;
this.paperHeight = height;
// TODO figure out whether we are animating or not and possibly delay this
// there will be one resize before paper is ready -- if so, dont call it
if (!this.paperReady) {
return;
}
this.refreshTree();
};
@ -294,7 +301,7 @@ GitVisuals.prototype.drawTreeFirstTime = function() {
visBranch.genGraphics(paper);
}, this);
this.refreshTree();
this.refreshTreeHarsh();
};