working on tree reload bugs

This commit is contained in:
Peter Cottle 2012-10-13 15:44:36 -07:00
parent 3bc67d66d3
commit ec5c40141c
3 changed files with 44 additions and 12 deletions

View file

@ -86,6 +86,12 @@ GitEngine.prototype.loadTree = function(tree) {
// first clear everything // first clear everything
this.removeAll(); this.removeAll();
this.instantiateFromTree(tree);
this.reloadGraphics();
};
GitEngine.prototype.instantiateFromTree = function(tree) {
// now we do the loading part // now we do the loading part
var createdSoFar = {}; var createdSoFar = {};
_.each(tree.commits, function(commitJSON) { _.each(tree.commits, function(commitJSON) {
@ -100,7 +106,18 @@ GitEngine.prototype.loadTree = function(tree) {
var HEAD = this.getOrMakeRecursive(tree, createdSoFar, tree.HEAD.id); var HEAD = this.getOrMakeRecursive(tree, createdSoFar, tree.HEAD.id);
this.HEAD = HEAD; this.HEAD = HEAD;
};
GitEngine.prototype.reloadGraphics = function() {
// this just basically makes the HEAD branch. the head branch really should have been
// a member of a collection and not this annoying edge case stuff...
console.log('calling when git engine ready');
gitVisuals.whenGitEngineReady(this);
// when the paper is ready
gitVisuals.drawTreeFirstTime();
console.log('refreshing hars');
gitVisuals.refreshTreeHarsh(); gitVisuals.refreshTreeHarsh();
}; };
@ -172,12 +189,7 @@ GitEngine.prototype.getOrMakeRecursive = function(tree, createdSoFar, objID) {
}; };
GitEngine.prototype.removeAll = function() { GitEngine.prototype.removeAll = function() {
this.branchCollection.each(function(branch) { gitVisuals.resetAll();
branch.get('visBranch').remove();
}, this);
this.commitCollection.each(function(commit) {
commit.get('visNode').removeAll();
}, this);
this.branchCollection.reset(); this.branchCollection.reset();
this.commitCollection.reset(); this.commitCollection.reset();

View file

@ -439,6 +439,7 @@ var VisNode = VisBase.extend({
setDepthBasedOn: function(depthIncrement) { setDepthBasedOn: function(depthIncrement) {
if (this.get('depth') === undefined) { if (this.get('depth') === undefined) {
debugger
throw new Error('no depth yet!'); throw new Error('no depth yet!');
} }
var pos = this.get('pos'); var pos = this.get('pos');

View file

@ -33,11 +33,33 @@ function GitVisuals(options) {
events.on('gitEngineReady', this.whenGitEngineReady, this); events.on('gitEngineReady', this.whenGitEngineReady, this);
} }
GitVisuals.prototype.resetAll = function() {
this.visEdgeCollection.each(function(visEdge) {
visEdge.remove();
}, this);
this.visBranchCollection.each(function(visBranch) {
visBranch.remove();
}, this);
_.each(this.visNodeMap, function(visNode) {
visNode.remove();
}, this);
this.visEdgeCollection.reset();
this.visBranchCollection.reset();
this.visNodeMap = {};
this.rootCommit = null;
this.commitMap = {};
};
GitVisuals.prototype.whenGitEngineReady = function(gitEngine) { GitVisuals.prototype.whenGitEngineReady = function(gitEngine) {
// seed this with the HEAD pseudo-branch // seed this with the HEAD pseudo-branch
this.visBranchCollection.add(new VisBranch({
var headBranch = new VisBranch({
branch: gitEngine.HEAD branch: gitEngine.HEAD
})); });
this.visBranchCollection.add(headBranch);
}; };
GitVisuals.prototype.getScreenBounds = function() { GitVisuals.prototype.getScreenBounds = function() {
@ -304,10 +326,7 @@ GitVisuals.prototype.calcDepth = function() {
var maxDepth = this.calcDepthRecursive(this.rootCommit, 0); var maxDepth = this.calcDepthRecursive(this.rootCommit, 0);
if (maxDepth > 15) { if (maxDepth > 15) {
// issue warning // issue warning
events.trigger('issueWarning', // TODO
'Max Depth Exceeded! Visuals may degrade here. ' +
'Please start fresh'
);
} }
var depthIncrement = this.getDepthIncrement(maxDepth); var depthIncrement = this.getDepthIncrement(maxDepth);