mirror of
https://github.com/pcottle/learnGitBranching.git
synced 2025-06-27 00:18:56 +02:00
global paper gone
This commit is contained in:
parent
4f8b3eb044
commit
5246580b27
3 changed files with 28 additions and 48 deletions
|
@ -283,7 +283,6 @@ var VisBranch = VisBase.extend({
|
||||||
},
|
},
|
||||||
|
|
||||||
genGraphics: function(paper) {
|
genGraphics: function(paper) {
|
||||||
|
|
||||||
var textPos = this.getTextPosition();
|
var textPos = this.getTextPosition();
|
||||||
var name = this.getName();
|
var name = this.getName();
|
||||||
var text;
|
var text;
|
||||||
|
@ -744,7 +743,9 @@ var VisNode = VisBase.extend({
|
||||||
}, this);
|
}, this);
|
||||||
},
|
},
|
||||||
|
|
||||||
genGraphics: function(paper) {
|
genGraphics: function() {
|
||||||
|
var paper = this.gitVisuals.paper;
|
||||||
|
|
||||||
var pos = this.getScreenCoords();
|
var pos = this.getScreenCoords();
|
||||||
var textPos = this.getTextScreenCoords();
|
var textPos = this.getTextScreenCoords();
|
||||||
|
|
||||||
|
|
|
@ -2,22 +2,24 @@ var Visualization = Backbone.View.extend({
|
||||||
initialize: function(options) {
|
initialize: function(options) {
|
||||||
var _this = this;
|
var _this = this;
|
||||||
Raphael(10, 10, 200, 200, function() {
|
Raphael(10, 10, 200, 200, function() {
|
||||||
|
|
||||||
// for some reason raphael calls this function with a predefined
|
// for some reason raphael calls this function with a predefined
|
||||||
// context...
|
// context...
|
||||||
// so switch it
|
// so switch it
|
||||||
paper = this;
|
|
||||||
_this.paperInitialize(this);
|
_this.paperInitialize(this);
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
|
|
||||||
paperInitialize: function(paper, options) {
|
paperInitialize: function(paper, options) {
|
||||||
this.paper = paper;
|
this.paper = paper;
|
||||||
|
|
||||||
this.commitCollection = new CommitCollection();
|
this.commitCollection = new CommitCollection();
|
||||||
this.branchCollection = new BranchCollection();
|
this.branchCollection = new BranchCollection();
|
||||||
|
|
||||||
this.gitVisuals = new GitVisuals({
|
this.gitVisuals = new GitVisuals({
|
||||||
commitCollection: this.commitCollection,
|
commitCollection: this.commitCollection,
|
||||||
branchCollection: this.branchCollection
|
branchCollection: this.branchCollection,
|
||||||
|
paper: this.paper
|
||||||
});
|
});
|
||||||
|
|
||||||
this.gitEngine = new GitEngine({
|
this.gitEngine = new GitEngine({
|
||||||
|
@ -46,7 +48,7 @@ var Visualization = Backbone.View.extend({
|
||||||
left: left + 'px',
|
left: left + 'px',
|
||||||
top: top + 'px'
|
top: top + 'px'
|
||||||
});
|
});
|
||||||
paper.setSize(width, height);
|
this.paper.setSize(width, height);
|
||||||
this.gitVisuals.canvasResize(width, height);
|
this.gitVisuals.canvasResize(width, height);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -66,9 +68,8 @@ function GitVisuals(options) {
|
||||||
this.upstreamBranchSet = null;
|
this.upstreamBranchSet = null;
|
||||||
this.upstreamHeadSet = null;
|
this.upstreamHeadSet = null;
|
||||||
|
|
||||||
this.paperReady = false;
|
this.paper = options.paper;
|
||||||
this.paperWidth = null;
|
this.gitReady = false;
|
||||||
this.paperHeight = null;
|
|
||||||
|
|
||||||
this.branchCollection.on('add', this.addBranchFromEvent, this);
|
this.branchCollection.on('add', this.addBranchFromEvent, this);
|
||||||
this.branchCollection.on('remove', this.removeBranch, this);
|
this.branchCollection.on('remove', this.removeBranch, this);
|
||||||
|
@ -140,7 +141,7 @@ GitVisuals.prototype.getScreenBounds = function() {
|
||||||
};
|
};
|
||||||
|
|
||||||
GitVisuals.prototype.toScreenCoords = function(pos) {
|
GitVisuals.prototype.toScreenCoords = function(pos) {
|
||||||
if (!this.paperWidth) {
|
if (!this.paper.width) {
|
||||||
throw new Error('being called too early for screen coords');
|
throw new Error('being called too early for screen coords');
|
||||||
}
|
}
|
||||||
var bounds = this.getScreenBounds();
|
var bounds = this.getScreenBounds();
|
||||||
|
@ -150,8 +151,8 @@ GitVisuals.prototype.toScreenCoords = function(pos) {
|
||||||
};
|
};
|
||||||
|
|
||||||
return {
|
return {
|
||||||
x: shrink(pos.x, this.paperWidth, bounds.widthPadding),
|
x: shrink(pos.x, this.paper.width, bounds.widthPadding),
|
||||||
y: shrink(pos.y, this.paperHeight, bounds.heightPadding)
|
y: shrink(pos.y, this.paper.height, bounds.heightPadding)
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -217,7 +218,7 @@ GitVisuals.prototype.genSnapshot = function() {
|
||||||
};
|
};
|
||||||
|
|
||||||
GitVisuals.prototype.refreshTree = function(speed) {
|
GitVisuals.prototype.refreshTree = function(speed) {
|
||||||
if (!this.paperReady) {
|
if (!this.gitReady) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -437,12 +438,12 @@ GitVisuals.prototype.animateNodePositions = function(speed) {
|
||||||
};
|
};
|
||||||
|
|
||||||
GitVisuals.prototype.turnOnPaper = function() {
|
GitVisuals.prototype.turnOnPaper = function() {
|
||||||
this.paperReady = false;
|
this.gitReady = false;
|
||||||
};
|
};
|
||||||
|
|
||||||
// does making an accessor method make it any less hacky? that is the true question
|
// does making an accessor method make it any less hacky? that is the true question
|
||||||
GitVisuals.prototype.turnOffPaper = function() {
|
GitVisuals.prototype.turnOffPaper = function() {
|
||||||
this.paperReady = true;
|
this.gitReady = true;
|
||||||
};
|
};
|
||||||
|
|
||||||
GitVisuals.prototype.addBranchFromEvent = function(branch, collection, index) {
|
GitVisuals.prototype.addBranchFromEvent = function(branch, collection, index) {
|
||||||
|
@ -465,8 +466,8 @@ GitVisuals.prototype.addBranch = function(branch, paperOverride) {
|
||||||
});
|
});
|
||||||
|
|
||||||
this.visBranchCollection.add(visBranch);
|
this.visBranchCollection.add(visBranch);
|
||||||
if (!paperOverride && this.paperReady) {
|
if (!paperOverride && this.gitReady) {
|
||||||
visBranch.genGraphics(paper);
|
visBranch.genGraphics(this.paper);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -512,13 +513,9 @@ GitVisuals.prototype.calcDepthRecursive = function(commit, depth) {
|
||||||
}, this);
|
}, this);
|
||||||
|
|
||||||
return maxDepth;
|
return maxDepth;
|
||||||
// TODO for merge commits, a specific fancy schamncy "main" commit line
|
|
||||||
};
|
};
|
||||||
|
|
||||||
GitVisuals.prototype.canvasResize = function(width, height) {
|
GitVisuals.prototype.canvasResize = function(width, height) {
|
||||||
this.paperWidth = width;
|
|
||||||
this.paperHeight = height;
|
|
||||||
|
|
||||||
// refresh when we are ready
|
// refresh when we are ready
|
||||||
if (GLOBAL.isAnimating) {
|
if (GLOBAL.isAnimating) {
|
||||||
events.trigger('processCommandFromEvent', 'refresh');
|
events.trigger('processCommandFromEvent', 'refresh');
|
||||||
|
@ -541,8 +538,8 @@ GitVisuals.prototype.addNode = function(id, commit) {
|
||||||
});
|
});
|
||||||
this.visNodeMap[id] = visNode;
|
this.visNodeMap[id] = visNode;
|
||||||
|
|
||||||
if (this.paperReady) {
|
if (this.gitReady) {
|
||||||
visNode.genGraphics(paper);
|
visNode.genGraphics(this.paper);
|
||||||
}
|
}
|
||||||
|
|
||||||
return visNode;
|
return visNode;
|
||||||
|
@ -565,8 +562,8 @@ GitVisuals.prototype.addEdge = function(idTail, idHead) {
|
||||||
});
|
});
|
||||||
this.visEdgeCollection.add(edge);
|
this.visEdgeCollection.add(edge);
|
||||||
|
|
||||||
if (this.paperReady) {
|
if (this.gitReady) {
|
||||||
edge.genGraphics(paper);
|
edge.genGraphics(this.paper);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -596,30 +593,30 @@ GitVisuals.prototype.visBranchesFront = function() {
|
||||||
};
|
};
|
||||||
|
|
||||||
GitVisuals.prototype.drawTreeFromReload = function() {
|
GitVisuals.prototype.drawTreeFromReload = function() {
|
||||||
this.paperReady = true;
|
this.gitReady = true;
|
||||||
this.calcTreeCoords();
|
this.calcTreeCoords();
|
||||||
|
|
||||||
this.visBranchCollection.each(function(visBranch) {
|
this.visBranchCollection.each(function(visBranch) {
|
||||||
visBranch.genGraphics(paper, {
|
visBranch.genGraphics(this.paper, {
|
||||||
fromReload: true
|
fromReload: true
|
||||||
});
|
});
|
||||||
}, this);
|
}, this);
|
||||||
};
|
};
|
||||||
|
|
||||||
GitVisuals.prototype.drawTreeFirstTime = function() {
|
GitVisuals.prototype.drawTreeFirstTime = function() {
|
||||||
this.paperReady = true;
|
this.gitReady = true;
|
||||||
this.calcTreeCoords();
|
this.calcTreeCoords();
|
||||||
|
|
||||||
_.each(this.visNodeMap, function(visNode) {
|
_.each(this.visNodeMap, function(visNode) {
|
||||||
visNode.genGraphics(paper);
|
visNode.genGraphics(this.paper);
|
||||||
}, this);
|
}, this);
|
||||||
|
|
||||||
this.visEdgeCollection.each(function(edge) {
|
this.visEdgeCollection.each(function(edge) {
|
||||||
edge.genGraphics(paper);
|
edge.genGraphics(this.paper);
|
||||||
}, this);
|
}, this);
|
||||||
|
|
||||||
this.visBranchCollection.each(function(visBranch) {
|
this.visBranchCollection.each(function(visBranch) {
|
||||||
visBranch.genGraphics(paper);
|
visBranch.genGraphics(this.paper);
|
||||||
}, this);
|
}, this);
|
||||||
|
|
||||||
this.zIndexReflow();
|
this.zIndexReflow();
|
||||||
|
@ -670,20 +667,3 @@ function randomHueString() {
|
||||||
return str;
|
return str;
|
||||||
};
|
};
|
||||||
|
|
||||||
function cuteSmallCircle(paper, x, y, options) {
|
|
||||||
var options = options || {};
|
|
||||||
var wantsSameColor = options.sameColor;
|
|
||||||
var radius = options.radius || 4;
|
|
||||||
|
|
||||||
var c = paper.circle(x, y, radius, radius);
|
|
||||||
if (!wantsSameColor) {
|
|
||||||
c.attr("fill","hsba(0.5,0.8,0.7,1)");
|
|
||||||
} else {
|
|
||||||
c.attr("fill","hsba(" + String(Math.random()) + ",0.8,0.7,1)");
|
|
||||||
}
|
|
||||||
|
|
||||||
c.attr("stroke","#FFF");
|
|
||||||
c.attr("stroke-width",2);
|
|
||||||
return c;
|
|
||||||
};
|
|
||||||
|
|
||||||
|
|
1
todo.txt
1
todo.txt
|
@ -14,7 +14,6 @@ Medium things:
|
||||||
|
|
||||||
Small things to implement:
|
Small things to implement:
|
||||||
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||||
- get rid of global paper references
|
|
||||||
|
|
||||||
Minor Bugs to fix:
|
Minor Bugs to fix:
|
||||||
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue