mirror of
https://github.com/pcottle/learnGitBranching.git
synced 2025-06-29 17:27:22 +02:00
Merging now worksgit status! and have some nice graph exploration
This commit is contained in:
parent
af76c03ad1
commit
6cb4c6b4a1
7 changed files with 206 additions and 52 deletions
|
@ -3,9 +3,20 @@ function GitVisuals() {
|
|||
|
||||
this.collection.on('change', _.bind(this.collectionChanged, this));
|
||||
events.on('drawGitVisuals', _.bind(this.drawVisuals, this));
|
||||
events.on('fixNodePositions', _.bind(this.fixNodes, this));
|
||||
}
|
||||
|
||||
GitVisuals.prototype.drawVisuals = function(sys, ctx, canvas) {
|
||||
|
||||
this.drawRefs(sys, ctx, canvas);
|
||||
};
|
||||
|
||||
GitVisuals.prototype.fixNodes = function(sys) {
|
||||
this.fixRootCommit(sys);
|
||||
};
|
||||
|
||||
GitVisuals.prototype.drawRefs = function(sys, ctx, canvas) {
|
||||
var sFill = graphics.refSelectedFontFill;
|
||||
// we need to draw refs here
|
||||
var branches = gitEngine.getBranches();
|
||||
var detachedHead = gitEngine.getDetachedHead();
|
||||
|
@ -14,21 +25,32 @@ GitVisuals.prototype.drawVisuals = 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 nodePoint = sys.toScreen(node._p);
|
||||
|
||||
// text position
|
||||
// TODO: better positioning of text here
|
||||
var screenPoint = _.clone(nodePoint);
|
||||
screenPoint.x += 100;
|
||||
|
||||
ctx.font = graphics.refFont;
|
||||
ctx.fillStyle = graphics.refFontFill;
|
||||
ctx.fillText(branch.id, screenPoint.x, screenPoint.y);
|
||||
|
||||
// also draw an arrow
|
||||
var offset = Math.round(graphics.nodeRadius * 2.5);
|
||||
this.drawArrow(ctx, screenPoint, nodePoint, graphics.arrowHeadWidth, offset);
|
||||
var fillStyle = branch.selected ? sFill : undefined;
|
||||
this.drawLabel(ctx, sys, node, branch.id, fillStyle);
|
||||
}, this));
|
||||
|
||||
if (detachedHead) {
|
||||
var node = HEAD.get('target').get('arborNode');
|
||||
this.drawLabel(ctx, sys, node, 'HEAD', sFill);
|
||||
}
|
||||
};
|
||||
|
||||
GitVisuals.prototype.drawLabel = function(ctx, sys, node, name, fillStyle) {
|
||||
fillStyle = fillStyle || graphics.refFontFill;
|
||||
|
||||
var nodePoint = sys.toScreen(node._p);
|
||||
// text position
|
||||
// TODO: better positioning of text here
|
||||
var screenPoint = _.clone(nodePoint);
|
||||
screenPoint.x += 100;
|
||||
|
||||
ctx.font = graphics.refFont;
|
||||
ctx.fillStyle = fillStyle;
|
||||
ctx.fillText(name, screenPoint.x, screenPoint.y);
|
||||
|
||||
// also draw an arrow
|
||||
var offset = Math.round(graphics.nodeRadius * 2.5);
|
||||
this.drawArrow(ctx, screenPoint, nodePoint, graphics.arrowHeadWidth, offset);
|
||||
};
|
||||
|
||||
GitVisuals.prototype.drawArrow = function(ctx, start, end, headWidth, offset) {
|
||||
|
@ -55,3 +77,15 @@ GitVisuals.prototype.drawArrow = function(ctx, start, end, headWidth, offset) {
|
|||
GitVisuals.prototype.collectionChanged = function() {
|
||||
// redo the algorithms
|
||||
};
|
||||
|
||||
GitVisuals.prototype.fixRootCommit = function(sys) {
|
||||
// get the viewports bottom center
|
||||
var bottomPosScreen = {
|
||||
x: Math.round($('#viewport').width() * 0.5),
|
||||
y: $('#viewport').height() - graphics.nodeRadius * 2.5
|
||||
};
|
||||
|
||||
var bottomPos = sys.fromScreen(bottomPosScreen);
|
||||
// fix the root commit to the bottom
|
||||
gitEngine.rootCommit.get('arborNode').p = bottomPos;
|
||||
};
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue