mirror of
https://github.com/pcottle/learnGitBranching.git
synced 2025-06-30 01:34:26 +02:00
[Origin] wow have tree string and undo working flawlessly, somewhat hacky but very robust all things considered
This commit is contained in:
parent
2938c3fb37
commit
cbcd489a31
10 changed files with 126 additions and 30 deletions
|
@ -197,9 +197,14 @@ GitEngine.prototype.instantiateFromTree = function(tree) {
|
|||
this.branchCollection.each(function(branch) {
|
||||
this.gitVisuals.addBranch(branch);
|
||||
}, this);
|
||||
|
||||
if (tree.originTree) {
|
||||
var treeString = JSON.stringify(tree.originTree);
|
||||
this.makeOrigin(treeString);
|
||||
}
|
||||
};
|
||||
|
||||
GitEngine.prototype.makeOrigin = function(tree) {
|
||||
GitEngine.prototype.makeOrigin = function(treeString) {
|
||||
if (this.hasOrigin()) {
|
||||
throw new GitError({
|
||||
msg: intl.str('git-error-options')
|
||||
|
@ -215,7 +220,7 @@ GitEngine.prototype.makeOrigin = function(tree) {
|
|||
var masterVis = this.gitVisuals.getVisualization();
|
||||
var originVis = masterVis.makeOrigin({
|
||||
localRepo: this,
|
||||
tree: this.getDefaultTree()
|
||||
treeString: treeString || this.printTree()
|
||||
});
|
||||
|
||||
// defer the starting of our animation until origin has been created
|
||||
|
@ -326,6 +331,13 @@ GitEngine.prototype.removeAll = function() {
|
|||
this.HEAD = null;
|
||||
this.rootCommit = null;
|
||||
|
||||
if (this.origin) {
|
||||
// we will restart all this jazz during init from tree
|
||||
this.origin.gitVisuals.getVisualization().tearDown();
|
||||
delete this.origin;
|
||||
this.gitVisuals.getVisualization().clearOrigin();
|
||||
}
|
||||
|
||||
this.gitVisuals.resetAll();
|
||||
};
|
||||
|
||||
|
@ -516,7 +528,7 @@ GitEngine.prototype.revertStarter = function() {
|
|||
};
|
||||
|
||||
GitEngine.prototype.originInitStarter = function() {
|
||||
this.makeOrigin(this.getDefaultTree());
|
||||
this.makeOrigin(this.printTree());
|
||||
};
|
||||
|
||||
GitEngine.prototype.revert = function(whichCommits) {
|
||||
|
|
|
@ -39,7 +39,8 @@ var VisBase = Backbone.Model.extend({
|
|||
if (instant) {
|
||||
this.get(key).attr(attr[key]);
|
||||
} else {
|
||||
this.get(key).stop().animate(attr[key], speed, easing);
|
||||
this.get(key).stop();
|
||||
this.get(key).animate(attr[key], speed, easing);
|
||||
// some keys dont support animating too, so set those instantly here
|
||||
_.forEach(this.getNonAnimateKeys(), function(nonAnimateKey) {
|
||||
if (attr[key] && attr[key][nonAnimateKey] !== undefined) {
|
||||
|
|
|
@ -167,7 +167,8 @@ var VisEdge = VisBase.extend({
|
|||
}
|
||||
|
||||
this.get('path').toBack();
|
||||
this.get('path').stop().animate(
|
||||
this.get('path').stop();
|
||||
this.get('path').animate(
|
||||
attr.path,
|
||||
speed !== undefined ? speed : this.get('animationSpeed'),
|
||||
easing || this.get('animationEasing')
|
||||
|
|
|
@ -277,7 +277,8 @@ var VisNode = VisBase.extend({
|
|||
_.each(this.get('outgoingEdges'), function(edge) {
|
||||
var headPos = edge.get('head').getScreenCoords();
|
||||
var path = edge.genSmoothBezierPathStringFromCoords(parentCoords, headPos);
|
||||
edge.get('path').stop().attr({
|
||||
edge.get('path').stop();
|
||||
edge.get('path').attr({
|
||||
path: path,
|
||||
opacity: 0
|
||||
});
|
||||
|
|
|
@ -86,6 +86,10 @@ var Visualization = Backbone.View.extend({
|
|||
this.customEvents.trigger('paperReady');
|
||||
},
|
||||
|
||||
clearOrigin: function() {
|
||||
delete this.originVis;
|
||||
},
|
||||
|
||||
makeOrigin: function(options) {
|
||||
// oh god, here we go. We basically do a bizarre form of composition here,
|
||||
// where this visualization actually contains another one of itself.
|
||||
|
@ -97,7 +101,7 @@ var Visualization = Backbone.View.extend({
|
|||
// never accept keyboard input or clicks
|
||||
noKeyboardInput: true,
|
||||
noClick: true,
|
||||
treeString: JSON.stringify(options.tree)
|
||||
treeString: options.treeString
|
||||
}
|
||||
));
|
||||
// return the newly created visualization which will soon have a git engine
|
||||
|
@ -105,9 +109,21 @@ var Visualization = Backbone.View.extend({
|
|||
},
|
||||
|
||||
originToo: function(methodToCall, args) {
|
||||
if (this.originVis) {
|
||||
this.originVis[methodToCall].apply(this.originVis, args);
|
||||
if (!this.originVis) {
|
||||
return;
|
||||
}
|
||||
var callMethod = _.bind(function() {
|
||||
this.originVis[methodToCall].apply(this.originVis, args);
|
||||
}, this);
|
||||
|
||||
if (this.originVis.paper) {
|
||||
callMethod();
|
||||
return;
|
||||
}
|
||||
// this is tricky -- sometimes we already have paper initialized but
|
||||
// our origin vis does not (since we kill that on every reset).
|
||||
// in this case lets bind to the custom event on paper ready
|
||||
this.originVis.customEvents.on('paperReady', callMethod);
|
||||
},
|
||||
|
||||
setTreeIndex: function(level) {
|
||||
|
@ -129,6 +145,7 @@ var Visualization = Backbone.View.extend({
|
|||
fadeTreeIn: function() {
|
||||
this.shown = true;
|
||||
$(this.paper.canvas).animate({opacity: 1}, this.getAnimationTime());
|
||||
|
||||
this.originToo('fadeTreeIn', arguments);
|
||||
},
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue