mirror of
https://github.com/pcottle/learnGitBranching.git
synced 2025-07-06 04:34:29 +02:00
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......
This commit is contained in:
parent
cf8e8557f3
commit
f5fcd32815
3 changed files with 28 additions and 7 deletions
|
@ -818,11 +818,12 @@ var Commit = Backbone.Model.extend({
|
||||||
},
|
},
|
||||||
|
|
||||||
addNodeToVisuals: function() {
|
addNodeToVisuals: function() {
|
||||||
this.set('arborNode', sys.addNode(this.get('id')));
|
var visNode = gitVisuals.addNode(this.get('id'));
|
||||||
|
this.set('visNode', visNode);
|
||||||
},
|
},
|
||||||
|
|
||||||
addEdgeToVisuals: function(parent) {
|
addEdgeToVisuals: function(parent) {
|
||||||
sys.addEdge(this.get('arborNode'), parent.get('arborNode'));
|
gitVisuals.addEdge(this.get('id'), parent.get('id'));
|
||||||
},
|
},
|
||||||
|
|
||||||
initialize: function() {
|
initialize: function() {
|
||||||
|
|
|
@ -33,10 +33,11 @@ $(document).ready(function(){
|
||||||
collection: commandCollection
|
collection: commandCollection
|
||||||
});
|
});
|
||||||
|
|
||||||
gitEngine = new GitEngine({
|
gitVisuals = new GitVisuals({
|
||||||
collection: commitCollection
|
collection: commitCollection
|
||||||
});
|
});
|
||||||
gitVisuals = new GitVisuals({
|
|
||||||
|
gitEngine = new GitEngine({
|
||||||
collection: commitCollection
|
collection: commitCollection
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
|
@ -1,11 +1,30 @@
|
||||||
function GitVisuals(options) {
|
function GitVisuals(options) {
|
||||||
this.collection = options.collection;
|
this.collection = options.collection;
|
||||||
|
this.nodeMap = {};
|
||||||
|
|
||||||
this.collection.on('change', _.bind(this.collectionChanged, this));
|
this.collection.on('change', _.bind(this.collectionChanged, this));
|
||||||
events.on('drawGitVisuals', _.bind(this.drawVisuals, this));
|
events.on('drawGitVisuals', _.bind(this.drawVisuals, this));
|
||||||
events.on('fixNodePositions', _.bind(this.fixNodes, 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) {
|
GitVisuals.prototype.drawVisuals = function(sys, ctx, canvas) {
|
||||||
this.drawRefs(sys, ctx, canvas);
|
this.drawRefs(sys, ctx, canvas);
|
||||||
};
|
};
|
||||||
|
@ -23,13 +42,13 @@ GitVisuals.prototype.drawRefs = function(sys, ctx, canvas) {
|
||||||
|
|
||||||
_.forEach(branches, _.bind(function(branch) {
|
_.forEach(branches, _.bind(function(branch) {
|
||||||
// get the location of the arbor node and then somehow draw the ref to the side?
|
// 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;
|
var fillStyle = branch.selected ? sFill : undefined;
|
||||||
this.drawLabel(ctx, sys, node, branch.id, fillStyle);
|
this.drawLabel(ctx, sys, node, branch.id, fillStyle);
|
||||||
}, this));
|
}, this));
|
||||||
|
|
||||||
if (detachedHead) {
|
if (detachedHead) {
|
||||||
var node = HEAD.get('target').get('arborNode');
|
var node = HEAD.get('target').get('visNode');
|
||||||
this.drawLabel(ctx, sys, node, 'HEAD', sFill);
|
this.drawLabel(ctx, sys, node, 'HEAD', sFill);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
@ -86,5 +105,5 @@ GitVisuals.prototype.fixRootCommit = function(sys) {
|
||||||
|
|
||||||
var bottomPos = sys.fromScreen(bottomPosScreen);
|
var bottomPos = sys.fromScreen(bottomPosScreen);
|
||||||
// fix the root commit to the bottom
|
// fix the root commit to the bottom
|
||||||
gitEngine.rootCommit.get('arborNode').p = bottomPos;
|
gitEngine.rootCommit.get('visNode').p = bottomPos;
|
||||||
};
|
};
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue