From 6e30bedd37857856680e77d5d1870f94fcd4c271 Mon Sep 17 00:00:00 2001 From: Peter Cottle Date: Sat, 13 Oct 2012 01:12:52 -0700 Subject: [PATCH] god damn took so long but now rebase is almost done --- src/animationFactory.js | 76 ++++++++++++++++++++++++++++++++++++----- src/constants.js | 2 +- src/tree.js | 32 +++++++++++++++++ 3 files changed, 101 insertions(+), 9 deletions(-) diff --git a/src/animationFactory.js b/src/animationFactory.js index dcbba96f..6089da64 100644 --- a/src/animationFactory.js +++ b/src/animationFactory.js @@ -66,7 +66,6 @@ AnimationFactory.prototype.overrideOpacityDepth3 = function(snapShot, opacity) { _.each(snapShot, function(visObj, visID) { newSnap[visID] = this.overrideOpacityDepth2(visObj, opacity); }, this); - console.log(newSnap); return newSnap; }; @@ -103,12 +102,22 @@ AnimationFactory.prototype.refreshTree = function(animationQueue) { }; AnimationFactory.prototype.rebaseAnimation = function(animationQueue, rebaseResponse, gitEngine) { + var rebaseSteps = rebaseResponse.rebaseSteps; // HIGHLIGHTING PART!!!! - var rebaseSteps = rebaseResponse.rebaseSteps; + var newVisNodes = []; + _.each(rebaseSteps, function(step) { + var visNode = step.newCommit.get('visNode'); - _.each(rebaseSteps, function(rebaseStep) { - var snapshotPart = this.genFromToSnapshotAnimation(rebaseStep.beforeSnapshot, rebaseStep.afterSnapshot); + newVisNodes.push(visNode); + visNode.setOpacity(0); + visNode.setOutgoingEdgesOpacity(0); + }, this); + + _.each(rebaseSteps, function(rebaseStep, index) { + var toOmit = newVisNodes.slice(0, index).concat(newVisNodes.slice(index + 1)); + + var snapshotPart = this.genFromToSnapshotAnimation(rebaseStep.beforeSnapshot, rebaseStep.afterSnapshot, toOmit); var birthPart = this.genCommitBirthClosureFromSnapshot(rebaseStep); var animation = function() { @@ -117,7 +126,8 @@ AnimationFactory.prototype.rebaseAnimation = function(animationQueue, rebaseResp }; animationQueue.add(new Animation({ - closure: animation + closure: animation, + duration: GRAPHICS.defaultAnimationTime })); /* @@ -126,11 +136,61 @@ AnimationFactory.prototype.rebaseAnimation = function(animationQueue, rebaseResp rebaseStep.beforeSnapshot rebaseStep.afterSnapshot*/ }, this); + + // need to delay to let bouncing finish + this.delay(animationQueue); + + this.refreshTree(animationQueue); }; -AnimationFactory.prototype.genFromToSnapshotAnimation = function(beforeSnapshot, afterSnapshot) { +AnimationFactory.prototype.delay = function(animationQueue, time) { + time = time || GRAPHICS.defaultAnimationTime; + animationQueue.add(new Animation({ + closure: function() { }, + duration: time + })); +}; + +AnimationFactory.prototype.genSetAllCommitOpacities = function(visNodes, opacity) { + // need to slice for closure + var nodesToAnimate = visNodes.slice(0); + return function() { - console.log('from', beforeSnapshot, 'to', afterSnapshot); - gitVisuals.animateAllFromAttrToAttr(beforeSnapshot, afterSnapshot); + _.each(nodesToAnimate, function(visNode) { + visNode.setOpacity(opacity); + visNode.setOutgoingEdgesOpacity(opacity); + }); + }; +}; + +AnimationFactory.prototype.stripObjectsFromSnapshot = function(snapShot, toOmit) { + var ids = []; + _.each(toOmit, function(obj) { + ids.push(obj.getID()); + }); + + var newSnapshot = {}; + _.each(snapShot, function(val, key) { + if (_.include(ids, key)) { + // omit + return; + } + newSnapshot[key] = val; + }, this); + return newSnapshot; +}; + +AnimationFactory.prototype.genFromToSnapshotAnimation = function(beforeSnapshot, afterSnapshot, commitsToOmit) { + // we also want to omit the commit outgoing edges + var toOmit = []; + _.each(commitsToOmit, function(visNode) { + toOmit.push(visNode); + toOmit = toOmit.concat(visNode.get('outgoingEdges')); + }); + + before = this.stripObjectsFromSnapshot(beforeSnapshot, toOmit); + after = this.stripObjectsFromSnapshot(afterSnapshot, toOmit); + return function() { + gitVisuals.animateAllFromAttrToAttr(before, after); }; }; diff --git a/src/constants.js b/src/constants.js index 2303388b..8d23fe99 100644 --- a/src/constants.js +++ b/src/constants.js @@ -19,7 +19,7 @@ var GRAPHICS = { nodeRadius: 17, curveControlPointOffset: 50, defaultEasing: 'easeInOut', - defaultAnimationTime: 300, + defaultAnimationTime: 1000, //rectFill: '#FF3A3A', rectFill: 'hsb(0.8816909813322127,0.7,1)', diff --git a/src/tree.js b/src/tree.js index 31e8f6ea..84a4161f 100644 --- a/src/tree.js +++ b/src/tree.js @@ -504,6 +504,14 @@ var VisNode = Backbone.Model.extend({ this.animateToAttr(toAttr, speed, easing); }, + animateToSnapshot: function(snapShot, speed, easing) { + console.log('animating to snapshot', snapShot, this.getID()); + if (!snapShot[this.getID()]) { + return; + } + this.animateToAttr(snapShot[this.getID()], speed, easing); + }, + animateToAttr: function(attr, speed, easing) { var func = 'animate'; if (speed == 0) { @@ -579,6 +587,12 @@ var VisNode = Backbone.Model.extend({ this.setOutgoingEdgesBirthPosition(this.getParentScreenCoords()); }, + setOutgoingEdgesOpacity: function(opacity) { + _.each(this.get('outgoingEdges'), function(edge) { + edge.setOpacity(opacity); + }); + }, + animateOutgoingEdgesToAttr: function(snapShot, speed, easing) { _.each(this.get('outgoingEdges'), function(edge) { var attr = snapShot[edge.getID()]; @@ -650,6 +664,18 @@ var VisNode = Backbone.Model.extend({ }); }, + setOpacity: function(opacity) { + opacity = (opacity === undefined) ? 1 : opacity; + + // set the opacity on my stuff + var keys = ['circle', 'text']; + _.each(keys, function(key) { + this.get(key).attr({ + opacity: opacity + }); + }, this); + }, + genGraphics: function(paper) { var pos = this.getScreenCoords(); var textPos = this.getTextScreenCoords(); @@ -768,6 +794,12 @@ var VisEdge = Backbone.Model.extend({ return GRAPHICS.visBranchStrokeColorNone; }, + setOpacity: function(opacity) { + opacity = (opacity === undefined) ? 1 : opacity; + + this.get('path').attr({opacity: opacity}); + }, + genGraphics: function(paper) { var pathString = this.getBezierCurve();