really hacky job of refs

This commit is contained in:
Peter Cottle 2012-09-19 20:10:58 -07:00
parent 8d6e835538
commit 18256dad4b
5 changed files with 103 additions and 9 deletions

View file

@ -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({
defaults: {
depth: undefined,
@ -163,3 +220,7 @@ var VisEdge = Backbone.Model.extend({
var VisEdgeCollection = Backbone.Collection.extend({
model: VisEdge
});
var VisBranchCollection = Backbone.Collection.extend({
model: VisBranch
});