mirror of
https://github.com/pcottle/learnGitBranching.git
synced 2025-06-27 16:38:50 +02:00
really hacky job of refs
This commit is contained in:
parent
8d6e835538
commit
18256dad4b
5 changed files with 103 additions and 9 deletions
|
@ -6,6 +6,10 @@ var CommandCollection = Backbone.Collection.extend({
|
||||||
model: Command,
|
model: Command,
|
||||||
});
|
});
|
||||||
|
|
||||||
|
var BranchCollection = Backbone.Collection.extend({
|
||||||
|
model: Branch
|
||||||
|
});
|
||||||
|
|
||||||
var CommandBuffer = Backbone.Model.extend({
|
var CommandBuffer = Backbone.Model.extend({
|
||||||
defaults: {
|
defaults: {
|
||||||
collection: null,
|
collection: null,
|
||||||
|
|
|
@ -11,7 +11,7 @@ function GitEngine(options) {
|
||||||
this.refs = {};
|
this.refs = {};
|
||||||
this.HEAD = null;
|
this.HEAD = null;
|
||||||
this.id_gen = 0;
|
this.id_gen = 0;
|
||||||
this.branches = [];
|
this.branches = options.branches;
|
||||||
this.collection = options.collection;
|
this.collection = options.collection;
|
||||||
|
|
||||||
// global variable to keep track of the options given
|
// global variable to keep track of the options given
|
||||||
|
@ -82,7 +82,7 @@ GitEngine.prototype.makeBranch = function(id, target) {
|
||||||
target: target,
|
target: target,
|
||||||
id: id
|
id: id
|
||||||
});
|
});
|
||||||
this.branches.push(branch);
|
this.branches.add(branch);
|
||||||
this.refs[branch.get('id')] = branch;
|
this.refs[branch.get('id')] = branch;
|
||||||
return branch;
|
return branch;
|
||||||
};
|
};
|
||||||
|
@ -93,7 +93,7 @@ GitEngine.prototype.getHead = function() {
|
||||||
|
|
||||||
GitEngine.prototype.getBranches = function() {
|
GitEngine.prototype.getBranches = function() {
|
||||||
var toReturn = [];
|
var toReturn = [];
|
||||||
_.each(this.branches, function(branch) {
|
this.branches.each(function(branch) {
|
||||||
toReturn.push({
|
toReturn.push({
|
||||||
id: branch.get('id'),
|
id: branch.get('id'),
|
||||||
selected: this.HEAD.get('target') === branch,
|
selected: this.HEAD.get('target') === branch,
|
||||||
|
@ -669,6 +669,7 @@ GitEngine.prototype.deleteBranch = function(name) {
|
||||||
target.delete();
|
target.delete();
|
||||||
delete this.refs[id];
|
delete this.refs[id];
|
||||||
// delete from array
|
// delete from array
|
||||||
|
// TODO
|
||||||
var toDelete = -1;
|
var toDelete = -1;
|
||||||
_.each(this.branches, function(branch, index) {
|
_.each(this.branches, function(branch, index) {
|
||||||
console.log(branch);
|
console.log(branch);
|
||||||
|
@ -799,7 +800,7 @@ var Ref = Backbone.Model.extend({
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
var Branch = Ref.extend({
|
var Branch = Ref.extend({
|
||||||
initialize: function() {
|
initialize: function() {
|
||||||
Ref.prototype.initialize.call(this);
|
Ref.prototype.initialize.call(this);
|
||||||
this.set('type', 'branch');
|
this.set('type', 'branch');
|
||||||
|
|
|
@ -15,6 +15,7 @@ $(document).ready(function(){
|
||||||
// the two major collections that affect everything
|
// the two major collections that affect everything
|
||||||
var commitCollection = new CommitCollection();
|
var commitCollection = new CommitCollection();
|
||||||
commandCollection = new CommandCollection();
|
commandCollection = new CommandCollection();
|
||||||
|
var branchCollection = new BranchCollection();
|
||||||
|
|
||||||
commandBuffer = new CommandBuffer({
|
commandBuffer = new CommandBuffer({
|
||||||
collection: commandCollection
|
collection: commandCollection
|
||||||
|
@ -30,11 +31,13 @@ $(document).ready(function(){
|
||||||
});
|
});
|
||||||
|
|
||||||
gitVisuals = new GitVisuals({
|
gitVisuals = new GitVisuals({
|
||||||
collection: commitCollection
|
commitCollection: commitCollection,
|
||||||
|
branchCollection: branchCollection
|
||||||
});
|
});
|
||||||
|
|
||||||
gitEngine = new GitEngine({
|
gitEngine = new GitEngine({
|
||||||
collection: commitCollection
|
collection: commitCollection,
|
||||||
|
branches: branchCollection
|
||||||
});
|
});
|
||||||
|
|
||||||
$('#commandTextField').focus();
|
$('#commandTextField').focus();
|
||||||
|
|
61
src/tree.js
61
src/tree.js
|
@ -1,3 +1,60 @@
|
||||||
|
var VisBranch = Backbone.Model.extend({
|
||||||
|
defaults: {
|
||||||
|
pos: null
|
||||||
|
},
|
||||||
|
|
||||||
|
validateAtInit: function() {
|
||||||
|
if (!this.get('branch')) {
|
||||||
|
throw new Error('need a branch!');
|
||||||
|
}
|
||||||
|
},
|
||||||
|
|
||||||
|
initialize: function() {
|
||||||
|
this.validateAtInit();
|
||||||
|
},
|
||||||
|
|
||||||
|
getPosition: function() {
|
||||||
|
var commit = this.get('branch').get('target');
|
||||||
|
var visNode = commit.get('visNode');
|
||||||
|
var pos = visNode.getScreenCoords();
|
||||||
|
return {
|
||||||
|
x: pos.x + 30,
|
||||||
|
y: pos.y
|
||||||
|
};
|
||||||
|
},
|
||||||
|
|
||||||
|
genGraphics: function(paper) {
|
||||||
|
var pos = this.getPosition();
|
||||||
|
if (!paper) {
|
||||||
|
console.log('no paper');
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
var name = this.get('branch').get('id');
|
||||||
|
var circle = paper.text(pos.x, pos.y, String(name));
|
||||||
|
this.set('text', circle);
|
||||||
|
},
|
||||||
|
|
||||||
|
animateUpdatedPos: function(paper) {
|
||||||
|
var pos = this.getPosition();
|
||||||
|
var t = this.get('text');
|
||||||
|
if (!t) {
|
||||||
|
this.genGraphics(paper);
|
||||||
|
t = this.get('text');
|
||||||
|
// TODO HACKY
|
||||||
|
}
|
||||||
|
this.get('text').toFront().stop().animate({
|
||||||
|
x: pos.x,
|
||||||
|
y: pos.y
|
||||||
|
},
|
||||||
|
300,
|
||||||
|
'easeInOut'
|
||||||
|
);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
var VisNode = Backbone.Model.extend({
|
var VisNode = Backbone.Model.extend({
|
||||||
defaults: {
|
defaults: {
|
||||||
depth: undefined,
|
depth: undefined,
|
||||||
|
@ -163,3 +220,7 @@ var VisEdge = Backbone.Model.extend({
|
||||||
var VisEdgeCollection = Backbone.Collection.extend({
|
var VisEdgeCollection = Backbone.Collection.extend({
|
||||||
model: VisEdge
|
model: VisEdge
|
||||||
});
|
});
|
||||||
|
|
||||||
|
var VisBranchCollection = Backbone.Collection.extend({
|
||||||
|
model: VisBranch
|
||||||
|
});
|
||||||
|
|
|
@ -1,7 +1,10 @@
|
||||||
function GitVisuals(options) {
|
function GitVisuals(options) {
|
||||||
this.commitCollection = options.collection;
|
this.commitCollection = options.commitCollection;
|
||||||
|
this.branchCollection = options.branchCollection;
|
||||||
this.visNodeMap = {};
|
this.visNodeMap = {};
|
||||||
|
|
||||||
this.edgeCollection = new VisEdgeCollection();
|
this.edgeCollection = new VisEdgeCollection();
|
||||||
|
this.visBranchCollection = new VisBranchCollection();
|
||||||
|
|
||||||
this.commitMap = {};
|
this.commitMap = {};
|
||||||
this.rootCommit = null;
|
this.rootCommit = null;
|
||||||
|
@ -11,6 +14,9 @@ function GitVisuals(options) {
|
||||||
this.paperHeight = null;
|
this.paperHeight = null;
|
||||||
|
|
||||||
this.commitCollection.on('change', this.collectionChanged, this);
|
this.commitCollection.on('change', this.collectionChanged, this);
|
||||||
|
|
||||||
|
this.branchCollection.on('add', this.addBranch, this);
|
||||||
|
this.branchCollection.on('remove', this.removeBranch, this);
|
||||||
|
|
||||||
events.on('canvasResize', _.bind(
|
events.on('canvasResize', _.bind(
|
||||||
this.canvasResize, this
|
this.canvasResize, this
|
||||||
|
@ -70,6 +76,7 @@ GitVisuals.prototype.refreshTree = function() {
|
||||||
this.calculateTreeCoords();
|
this.calculateTreeCoords();
|
||||||
this.animateNodePositions();
|
this.animateNodePositions();
|
||||||
this.animateEdges();
|
this.animateEdges();
|
||||||
|
this.animateRefs();
|
||||||
};
|
};
|
||||||
|
|
||||||
GitVisuals.prototype.calculateTreeCoords = function() {
|
GitVisuals.prototype.calculateTreeCoords = function() {
|
||||||
|
@ -104,8 +111,6 @@ GitVisuals.prototype.assignBoundsRecursive = function(commit, min, max) {
|
||||||
// I always center myself within my bounds
|
// I always center myself within my bounds
|
||||||
var myWidthPos = (min + max) / 2.0;
|
var myWidthPos = (min + max) / 2.0;
|
||||||
commit.get('visNode').get('pos').x = myWidthPos;
|
commit.get('visNode').get('pos').x = myWidthPos;
|
||||||
// TODO get rid of
|
|
||||||
// commit.get('visNode').get('pos').x = Math.random();
|
|
||||||
|
|
||||||
if (commit.get('children').length == 0) {
|
if (commit.get('children').length == 0) {
|
||||||
return;
|
return;
|
||||||
|
@ -167,6 +172,22 @@ GitVisuals.prototype.animateNodePositions = function() {
|
||||||
}, this);
|
}, this);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
GitVisuals.prototype.addBranch = function(branch) {
|
||||||
|
var visBranch = new VisBranch({
|
||||||
|
branch: branch
|
||||||
|
});
|
||||||
|
this.visBranchCollection.add(visBranch);
|
||||||
|
if (this.paperReady) {
|
||||||
|
visBranch.genGraphics();
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
GitVisuals.prototype.animateRefs = function() {
|
||||||
|
this.visBranchCollection.each(function(visBranch) {
|
||||||
|
visBranch.animateUpdatedPos(paper);
|
||||||
|
}, this);
|
||||||
|
};
|
||||||
|
|
||||||
GitVisuals.prototype.animateEdges = function() {
|
GitVisuals.prototype.animateEdges = function() {
|
||||||
this.edgeCollection.each(function(edge) {
|
this.edgeCollection.each(function(edge) {
|
||||||
edge.animateUpdatedPath();
|
edge.animateUpdatedPath();
|
||||||
|
@ -254,6 +275,10 @@ GitVisuals.prototype.drawTreeFirstTime = function() {
|
||||||
this.edgeCollection.each(function(edge) {
|
this.edgeCollection.each(function(edge) {
|
||||||
edge.genGraphics(paper);
|
edge.genGraphics(paper);
|
||||||
}, this);
|
}, this);
|
||||||
|
|
||||||
|
this.visBranchCollection.each(function(visBranch) {
|
||||||
|
visBranch.genGraphics(paper);
|
||||||
|
}, this);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue