more progress on arrows and stuff

This commit is contained in:
Peter Cottle 2012-09-17 13:12:42 -07:00
parent cc65ae7491
commit a229bc2f41
7 changed files with 30 additions and 14 deletions

View file

@ -100,6 +100,12 @@ var Command = Backbone.Model.extend({
git <command> [<args>] \ git <command> [<args>] \
") ")
}); });
}],
[/^refresh$/, function() {
events.trigger('refreshTree');
throw new CommandResult({
msg: "Refreshing tree..."
});
}] }]
]; ];
}, },

View file

@ -70,6 +70,7 @@ var CommandPromptView = Backbone.View.extend({
_.each(value.split(';'), _.bind(function(command) { _.each(value.split(';'), _.bind(function(command) {
command = command.replace(/^(\s+)/, ''); command = command.replace(/^(\s+)/, '');
command = command.replace(/(\s+)$/, ''); command = command.replace(/(\s+)$/, '');
console.log('the command is', command);
if (command.length) { if (command.length) {
this.addToCollection(command); this.addToCollection(command);
} }

View file

@ -40,6 +40,9 @@ GitEngine.prototype.init = function() {
// commit once to get things going // commit once to get things going
this.commit(); this.commit();
// update tree
events.trigger('treeRefresh');
}; };
GitEngine.prototype.getDetachedHead = function() { GitEngine.prototype.getDetachedHead = function() {
@ -713,7 +716,7 @@ GitEngine.prototype.dispatch = function(command, callback) {
} }
})); }));
// TODO (get rid of) // TODO (get rid of)
for (var i = 0; i < 3; i++) { for (var i = 0; i < 1; i++) {
this.animationQueue.add(new Animation({closure: function() { console.log(Math.random()); }})); this.animationQueue.add(new Animation({closure: function() { console.log(Math.random()); }}));
} }

View file

@ -63,7 +63,6 @@ function windowResize() {
var width = el.clientWidth - smaller; var width = el.clientWidth - smaller;
var height = el.clientHeight - smaller; var height = el.clientHeight - smaller;
console.log('setting to', left, top, width, height);
$(paper.canvas).css({ $(paper.canvas).css({
left: left + 'px', left: left + 'px',
top: top + 'px' top: top + 'px'

View file

@ -39,7 +39,7 @@ var VisNode = Backbone.Model.extend({
animateUpdatedPosition: function(speed, easing) { animateUpdatedPosition: function(speed, easing) {
var pos = this.getScreenCoords(); var pos = this.getScreenCoords();
this.get('circle').animate({ this.get('circle').stop().animate({
cx: pos.x, cx: pos.x,
cy: pos.y cy: pos.y
}, },
@ -90,9 +90,6 @@ var VisEdge = Backbone.Model.extend({
genSmoothBezierPathString: function(tail, head) { genSmoothBezierPathString: function(tail, head) {
var tailPos = tail.getScreenCoords(); var tailPos = tail.getScreenCoords();
var headPos = head.getScreenCoords(); var headPos = head.getScreenCoords();
// first offset tail and head by radii
// we need to generate the path and control points for the bezier. format // we need to generate the path and control points for the bezier. format
// is M(move abs) C (curve to) (control point 1) (control point 2) (final point) // is M(move abs) C (curve to) (control point 1) (control point 2) (final point)
// the control points have to be __below__ to get the curve starting off straight. // the control points have to be __below__ to get the curve starting off straight.
@ -100,14 +97,18 @@ var VisEdge = Backbone.Model.extend({
var coords = function(pos) { var coords = function(pos) {
return String(Math.round(pos.x)) + ',' + String(Math.round(pos.y)); return String(Math.round(pos.x)) + ',' + String(Math.round(pos.y));
}; };
var offset = function(pos, dir, offset) { var offset = function(pos, dir, delta) {
offset = offset || GRAPHICS.curveControlPointOffset; delta = delta || GRAPHICS.curveControlPointOffset;
return { return {
x: pos.x, x: pos.x,
y: pos.y + GRAPHICS.curveControlPointOffset * dir y: pos.y + delta * dir
}; };
}; };
// first offset tail and head by radii
tailPos = offset(tailPos, -1, tail.getRadius());
headPos = offset(headPos, 1, head.getRadius());
var str = ''; var str = '';
// first move to bottom of tail // first move to bottom of tail
str += 'M' + coords(tailPos) + ' '; str += 'M' + coords(tailPos) + ' ';
@ -134,7 +135,7 @@ var VisEdge = Backbone.Model.extend({
animateUpdatedPath: function(speed, easing) { animateUpdatedPath: function(speed, easing) {
var newPath = this.getBezierCurve(); var newPath = this.getBezierCurve();
this.get('path').toBack(); this.get('path').toBack();
this.get('path').animate({ this.get('path').stop().animate({
path: newPath path: newPath
}, },
speed || this.get('animationSpeed'), speed || this.get('animationSpeed'),

View file

@ -1,5 +1,4 @@
function GitVisuals(options) { function GitVisuals(options) {
// the
this.commitCollection = options.collection; this.commitCollection = options.collection;
this.visNodeMap = {}; this.visNodeMap = {};
this.edgeCollection = new VisEdgeCollection(); this.edgeCollection = new VisEdgeCollection();
@ -19,6 +18,9 @@ function GitVisuals(options) {
events.on('raphaelReady', _.bind( events.on('raphaelReady', _.bind(
this.drawTreeFirstTime, this this.drawTreeFirstTime, this
)); ));
events.on('refreshTree', _.bind(
this.refreshTree, this
));
} }
GitVisuals.prototype.getScreenBounds = function() { GitVisuals.prototype.getScreenBounds = function() {
@ -63,6 +65,8 @@ GitVisuals.prototype.toScreenCoords = function(pos) {
**************************************/ **************************************/
GitVisuals.prototype.refreshTree = function() { GitVisuals.prototype.refreshTree = function() {
if (!this.paperReady) { return; }
this.calculateTreeCoords(); this.calculateTreeCoords();
this.animateNodePositions(); this.animateNodePositions();
this.animateEdges(); this.animateEdges();
@ -159,7 +163,6 @@ GitVisuals.prototype.calcDepth = function() {
GitVisuals.prototype.animateNodePositions = function() { GitVisuals.prototype.animateNodePositions = function() {
_.each(this.visNodeMap, function(visNode) { _.each(this.visNodeMap, function(visNode) {
console.log(visNode);
visNode.animateUpdatedPosition(); visNode.animateUpdatedPosition();
}, this); }, this);
}; };
@ -178,8 +181,6 @@ GitVisuals.prototype.getDepthIncrement = function(maxDepth) {
}; };
GitVisuals.prototype.calcDepthRecursive = function(commit, depth) { GitVisuals.prototype.calcDepthRecursive = function(commit, depth) {
console.log('calculating depth recursive for ', commit);
commit.get('visNode').set('depth', depth); commit.get('visNode').set('depth', depth);
var children = commit.get('children'); var children = commit.get('children');
@ -196,6 +197,8 @@ GitVisuals.prototype.calcDepthRecursive = function(commit, depth) {
GitVisuals.prototype.canvasResize = function(width, height) { GitVisuals.prototype.canvasResize = function(width, height) {
this.paperWidth = width; this.paperWidth = width;
this.paperHeight = height; this.paperHeight = height;
// TODO figure out whether we are animating or not and possibly delay this
this.refreshTree();
}; };
GitVisuals.prototype.addNode = function(id, commit) { GitVisuals.prototype.addNode = function(id, commit) {

3
todo.txt Normal file
View file

@ -0,0 +1,3 @@
SAFE calling on tree animation -- so it will update when necessary (AnimationArbiter class)