BOOM\! Got branch stack ordering down

This commit is contained in:
Peter Cottle 2012-09-28 11:51:18 -07:00
parent 499961f3b5
commit 6e7e06277e
4 changed files with 76 additions and 12 deletions

View file

@ -20,11 +20,12 @@ var GRAPHICS = {
defaultAnimationTime: 300, defaultAnimationTime: 300,
rectFill: '#FF3A3A', rectFill: '#FF3A3A',
rectStroke: '#FFF', rectStroke: '#FFF',
rectStrokeWidth: '3' rectStrokeWidth: '3',
multiBranchY: 20,
}; };
/** /**
* Graphics style * Graphics style -- DEPRECATED
*/ */
var graphics = { var graphics = {
// colors // colors
@ -46,7 +47,7 @@ var graphics = {
arrowFill: '#FFF', arrowFill: '#FFF',
arrowStroke: '#000', arrowStroke: '#000',
arrowWidth: 4, arrowWidth: 4,
arrowHeadWidth: 5 arrowHeadWidth: 5,
}; };
function randomString(string_length) { function randomString(string_length) {

View file

@ -32,11 +32,28 @@ var VisBranch = Backbone.Model.extend({
return visNode.getScreenCoords(); return visNode.getScreenCoords();
}, },
getBranchStackIndex: function() {
var myArray = this.getBranchStackArray();
return myArray.indexOf(this.get('branch').get('id'));
},
getBranchStackLength: function() {
return this.getBranchStackArray().length;
},
getBranchStackArray: function() {
return gitVisuals.branchStackMap[this.get('branch').get('target').get('id')];
},
getTextPosition: function() { getTextPosition: function() {
var pos = this.getCommitPosition(); var pos = this.getCommitPosition();
// then order yourself accordingly. we use alphabetical sorting
// so everything is independent
var myPos = this.getBranchStackIndex();
return { return {
x: pos.x + this.get('offsetX'), x: pos.x + this.get('offsetX'),
y: pos.y + this.get('offsetY') y: pos.y + myPos * GRAPHICS.multiBranchY + this.get('offsetY')
}; };
}, },
@ -51,6 +68,7 @@ var VisBranch = Backbone.Model.extend({
}, },
getArrowPath: function() { getArrowPath: function() {
// should make these util functions...
var offset2d = function(pos, x, y) { var offset2d = function(pos, x, y) {
return { return {
x: pos.x + x, x: pos.x + x,
@ -62,7 +80,7 @@ var VisBranch = Backbone.Model.extend({
}; };
// worst variable names evar // worst variable names evar!!! warning
// start at rect corner // start at rect corner
var overlap = 5; var overlap = 5;
var startPos = offset2d(this.getRectPosition(), overlap, this.get('arrowInnerMargin')); var startPos = offset2d(this.getRectPosition(), overlap, this.get('arrowInnerMargin'));
@ -75,7 +93,7 @@ var VisBranch = Backbone.Model.extend({
-this.get('arrowLength') * this.get('arrowRatio'), 0); -this.get('arrowLength') * this.get('arrowRatio'), 0);
// get the next three points in backwards order // get the next three points in backwards order
var end = offset2d(this.getRectPosition(), overlap, this.getRectSize().h - this.get('arrowInnerMargin')); var end = offset2d(this.getRectPosition(), overlap, this.getSingleRectSize().h - this.get('arrowInnerMargin'));
var beforeEnd = offset2d(end, -this.get('arrowLength'), 0); var beforeEnd = offset2d(end, -this.get('arrowLength'), 0);
var beforeBeforeEnd = offset2d(beforeEnd, 0, this.get('arrowEdgeHeight')); var beforeBeforeEnd = offset2d(beforeEnd, 0, this.get('arrowEdgeHeight'));
@ -98,9 +116,8 @@ var VisBranch = Backbone.Model.extend({
}; };
}, },
getRectSize: function() { getSingleRectSize: function() {
var textSize = this.getTextSize(); var textSize = this.getTextSize();
// enforce padding
var vPad = this.get('vPad'); var vPad = this.get('vPad');
var hPad = this.get('hPad'); var hPad = this.get('hPad');
return { return {
@ -109,6 +126,20 @@ var VisBranch = Backbone.Model.extend({
}; };
}, },
getRectSize: function() {
var textSize = this.getTextSize();
// enforce padding
var vPad = this.get('vPad');
var hPad = this.get('hPad');
// number of other branch names we are housing
var totalNum = this.getBranchStackLength();
return {
w: textSize.w + vPad * 2,
h: textSize.h * totalNum + hPad * 2
};
},
getName: function() { getName: function() {
var name = this.get('branch').get('id'); var name = this.get('branch').get('id');
var selected = gitEngine.HEAD.get('target').get('id'); var selected = gitEngine.HEAD.get('target').get('id');
@ -117,6 +148,10 @@ var VisBranch = Backbone.Model.extend({
return name + add; return name + add;
}, },
textToFront: function() {
this.get('text').toFront();
},
genGraphics: function(paper) { genGraphics: function(paper) {
var textPos = this.getTextPosition(); var textPos = this.getTextPosition();
@ -153,6 +188,7 @@ var VisBranch = Backbone.Model.extend({
animateUpdatedPos: function(speed, easing) { animateUpdatedPos: function(speed, easing) {
var s = speed !== undefined ? speed : this.get('animationSpeed'); var s = speed !== undefined ? speed : this.get('animationSpeed');
var e = easing || this.get('animationEasing'); var e = easing || this.get('animationEasing');
var masterOpacity = this.getBranchStackIndex() == 0 ? 1 : 0.0;
this.get('text').attr({ this.get('text').attr({
text: this.getName() text: this.getName()
@ -169,12 +205,14 @@ var VisBranch = Backbone.Model.extend({
x: rectPos.x, x: rectPos.x,
y: rectPos.y, y: rectPos.y,
width: rectSize.w, width: rectSize.w,
height: rectSize.h height: rectSize.h,
opacity: masterOpacity,
}, s, e); }, s, e);
var arrowPath = this.getArrowPath(); var arrowPath = this.getArrowPath();
this.get('arrow').stop().animate({ this.get('arrow').stop().animate({
path: arrowPath path: arrowPath,
opacity: masterOpacity
}, s, e); }, s, e);
} }
}); });

View file

@ -8,6 +8,7 @@ function GitVisuals(options) {
this.commitMap = {}; this.commitMap = {};
this.rootCommit = null; this.rootCommit = null;
this.branchStackMap = {};
this.paperReady = false; this.paperReady = false;
this.paperWidth = null; this.paperWidth = null;
@ -95,6 +96,21 @@ GitVisuals.prototype.calculateTreeCoords = function() {
this.calcDepth(); this.calcDepth();
this.calcWidth(); this.calcWidth();
this.calcBranchStacks();
};
GitVisuals.prototype.calcBranchStacks = function() {
var branches = gitEngine.getBranches();
var map = {};
_.each(branches, function(branch) {
var thisId = branch.target.get('id');
map[thisId] = map[thisId] || [];
map[thisId].push(branch.id);
map[thisId].sort();
});
this.branchStackMap = map;
}; };
GitVisuals.prototype.calcWidth = function() { GitVisuals.prototype.calcWidth = function() {
@ -195,6 +211,7 @@ GitVisuals.prototype.addBranch = function(branch) {
this.visBranchCollection.add(visBranch); this.visBranchCollection.add(visBranch);
if (this.paperReady) { if (this.paperReady) {
visBranch.genGraphics(paper); visBranch.genGraphics(paper);
this.zIndexReflow();
} }
}; };
@ -287,8 +304,16 @@ GitVisuals.prototype.collectionChanged = function() {
// redo stuff // redo stuff
}; };
GitVisuals.prototype.zIndexReflow = function() {
this.visBranchCollection.each(function(vBranch) {
vBranch.textToFront();
});
};
GitVisuals.prototype.drawTreeFirstTime = function() { GitVisuals.prototype.drawTreeFirstTime = function() {
this.paperReady = true; this.paperReady = true;
this.calculateTreeCoords();
_.each(this.visNodeMap, function(visNode) { _.each(this.visNodeMap, function(visNode) {
visNode.genGraphics(paper); visNode.genGraphics(paper);
}, this); }, this);
@ -301,7 +326,7 @@ GitVisuals.prototype.drawTreeFirstTime = function() {
visBranch.genGraphics(paper); visBranch.genGraphics(paper);
}, this); }, this);
this.refreshTreeHarsh(); this.zIndexReflow();
}; };

View file

@ -11,11 +11,11 @@ animation factory? stuff like:
-clearHighlightsAllNodes -clearHighlightsAllNodes
ALSO other big things: ALSO other big things:
- Text on commit nodes - Text on commit nodes
- Division in their rings based on how many / what branches they are part of - Division in their rings based on how many / what branches they are part of
- Color on branch edges??
- Commits go transparent when no longer downstream of anything (also their weights are adjusted? and sent to back?) - Commits go transparent when no longer downstream of anything (also their weights are adjusted? and sent to back?)