diff --git a/src/git.js b/src/git.js index ec26adc0..fa495976 100644 --- a/src/git.js +++ b/src/git.js @@ -85,7 +85,13 @@ GitEngine.prototype.exportTree = function() { GitEngine.prototype.loadTree = function(tree) { // first clear everything this.removeAll(); + + this.instantiateFromTree(tree); + this.reloadGraphics(); +}; + +GitEngine.prototype.instantiateFromTree = function(tree) { // now we do the loading part var createdSoFar = {}; _.each(tree.commits, function(commitJSON) { @@ -100,7 +106,18 @@ GitEngine.prototype.loadTree = function(tree) { var HEAD = this.getOrMakeRecursive(tree, createdSoFar, tree.HEAD.id); 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(); }; @@ -172,12 +189,7 @@ GitEngine.prototype.getOrMakeRecursive = function(tree, createdSoFar, objID) { }; GitEngine.prototype.removeAll = function() { - this.branchCollection.each(function(branch) { - branch.get('visBranch').remove(); - }, this); - this.commitCollection.each(function(commit) { - commit.get('visNode').removeAll(); - }, this); + gitVisuals.resetAll(); this.branchCollection.reset(); this.commitCollection.reset(); diff --git a/src/tree.js b/src/tree.js index ef65edac..6f9cb7a1 100644 --- a/src/tree.js +++ b/src/tree.js @@ -439,6 +439,7 @@ var VisNode = VisBase.extend({ setDepthBasedOn: function(depthIncrement) { if (this.get('depth') === undefined) { + debugger throw new Error('no depth yet!'); } var pos = this.get('pos'); diff --git a/src/visuals.js b/src/visuals.js index a1ca4a87..885877cd 100644 --- a/src/visuals.js +++ b/src/visuals.js @@ -33,11 +33,33 @@ function GitVisuals(options) { 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) { // seed this with the HEAD pseudo-branch - this.visBranchCollection.add(new VisBranch({ + + var headBranch = new VisBranch({ branch: gitEngine.HEAD - })); + }); + + this.visBranchCollection.add(headBranch); }; GitVisuals.prototype.getScreenBounds = function() { @@ -304,10 +326,7 @@ GitVisuals.prototype.calcDepth = function() { var maxDepth = this.calcDepthRecursive(this.rootCommit, 0); if (maxDepth > 15) { // issue warning - events.trigger('issueWarning', - 'Max Depth Exceeded! Visuals may degrade here. ' + - 'Please start fresh' - ); + // TODO } var depthIncrement = this.getDepthIncrement(maxDepth);