From f5fcd3281513730334e2f0e26b0dfff726388a0f Mon Sep 17 00:00:00 2001 From: Peter Cottle Date: Sun, 16 Sep 2012 10:18:58 -0700 Subject: [PATCH] ok, decoupled vis details from git engine. now for big switch away from arbor.js to raphael with my own tree drawing algorithm. deep breath...... --- src/git.js | 5 +++-- src/mine.js | 5 +++-- src/visuals.js | 25 ++++++++++++++++++++++--- 3 files changed, 28 insertions(+), 7 deletions(-) diff --git a/src/git.js b/src/git.js index c66193dc..01b2edfc 100644 --- a/src/git.js +++ b/src/git.js @@ -818,11 +818,12 @@ var Commit = Backbone.Model.extend({ }, addNodeToVisuals: function() { - this.set('arborNode', sys.addNode(this.get('id'))); + var visNode = gitVisuals.addNode(this.get('id')); + this.set('visNode', visNode); }, addEdgeToVisuals: function(parent) { - sys.addEdge(this.get('arborNode'), parent.get('arborNode')); + gitVisuals.addEdge(this.get('id'), parent.get('id')); }, initialize: function() { diff --git a/src/mine.js b/src/mine.js index ef76ad52..fe945bfa 100644 --- a/src/mine.js +++ b/src/mine.js @@ -33,10 +33,11 @@ $(document).ready(function(){ collection: commandCollection }); - gitEngine = new GitEngine({ + gitVisuals = new GitVisuals({ collection: commitCollection }); - gitVisuals = new GitVisuals({ + + gitEngine = new GitEngine({ collection: commitCollection }); diff --git a/src/visuals.js b/src/visuals.js index 726822f6..6a70ac2a 100644 --- a/src/visuals.js +++ b/src/visuals.js @@ -1,11 +1,30 @@ function GitVisuals(options) { this.collection = options.collection; + this.nodeMap = {}; this.collection.on('change', _.bind(this.collectionChanged, this)); events.on('drawGitVisuals', _.bind(this.drawVisuals, this)); events.on('fixNodePositions', _.bind(this.fixNodes, this)); } +GitVisuals.prototype.addNode = function(id) { + var visNode = sys.addNode(id); + this.nodeMap[id] = visNode; + return visNode; +}; + +GitVisuals.prototype.addEdge = function(idTail, idHead) { + var visNodeTail = this.nodeMap[idTail]; + var visNodeHead = this.nodeMap[idHead]; + + if (!visNodeTail || !visNodeHead) { + throw new Error('one of the ids in (' + idTail + + ', ' + idHead + ') does not exist'); + } + + sys.addEdge(visNodeTail, visNodeHead); +}; + GitVisuals.prototype.drawVisuals = function(sys, ctx, canvas) { this.drawRefs(sys, ctx, canvas); }; @@ -23,13 +42,13 @@ GitVisuals.prototype.drawRefs = function(sys, ctx, canvas) { _.forEach(branches, _.bind(function(branch) { // get the location of the arbor node and then somehow draw the ref to the side? - var node = branch.target.get('arborNode'); + var node = branch.target.get('visNode'); var fillStyle = branch.selected ? sFill : undefined; this.drawLabel(ctx, sys, node, branch.id, fillStyle); }, this)); if (detachedHead) { - var node = HEAD.get('target').get('arborNode'); + var node = HEAD.get('target').get('visNode'); this.drawLabel(ctx, sys, node, 'HEAD', sFill); } }; @@ -86,5 +105,5 @@ GitVisuals.prototype.fixRootCommit = function(sys) { var bottomPos = sys.fromScreen(bottomPosScreen); // fix the root commit to the bottom - gitEngine.rootCommit.get('arborNode').p = bottomPos; + gitEngine.rootCommit.get('visNode').p = bottomPos; };