mirror of
https://github.com/pcottle/learnGitBranching.git
synced 2025-06-25 15:38:33 +02:00
bearable
This commit is contained in:
parent
5754238864
commit
e4b82fd653
10 changed files with 336 additions and 50 deletions
|
@ -495,9 +495,10 @@ GitVisuals.prototype.maxWidthRecursive = function(commit) {
|
|||
return maxWidth;
|
||||
};
|
||||
|
||||
GitVisuals.prototype.assignBoundsRecursive = function(commit, min, max) {
|
||||
// I always center myself within my bounds
|
||||
var myWidthPos = (min + max) / 2.0;
|
||||
GitVisuals.prototype.assignBoundsRecursive = function(commit, min, max, centerFrac) {
|
||||
centerFrac = (centerFrac === undefined) ? 0.5 : centerFrac;
|
||||
// I always position myself within my bounds
|
||||
var myWidthPos = min + (max - min) * centerFrac;
|
||||
commit.get('visNode').get('pos').x = myWidthPos;
|
||||
|
||||
if (commit.get('children').length === 0) {
|
||||
|
@ -516,23 +517,29 @@ GitVisuals.prototype.assignBoundsRecursive = function(commit, min, max) {
|
|||
}
|
||||
}, this);
|
||||
|
||||
var checkPortion = function(portion, index) {
|
||||
if (myLength < 0.99 || children.length < 2) {
|
||||
return portion;
|
||||
// TODO: refactor into another method
|
||||
var getCenterFrac = function(index, centerFrac) {
|
||||
if (myLength < 0.99) {
|
||||
if (children.length < 2) {
|
||||
return centerFrac;
|
||||
} else {
|
||||
return 0.5;
|
||||
}
|
||||
}
|
||||
if (children.length < 2) {
|
||||
return 0.5;
|
||||
}
|
||||
// we introduce a VERY specific rule here, to push out
|
||||
// the first "divergence" of the graph
|
||||
if (index === 0) {
|
||||
portion *= 1/3;
|
||||
return 1/3;
|
||||
} else if (index === children.length - 1) {
|
||||
portion *= 5/3;
|
||||
return 2/3;
|
||||
}
|
||||
return portion;
|
||||
return centerFrac;
|
||||
};
|
||||
|
||||
var prevBound = min;
|
||||
// now go through and do everything
|
||||
// TODO: order so the max width children are in the middle!!
|
||||
_.each(children, function(child, index) {
|
||||
if (!child.isMainParent(commit)) {
|
||||
return;
|
||||
|
@ -540,12 +547,12 @@ GitVisuals.prototype.assignBoundsRecursive = function(commit, min, max) {
|
|||
|
||||
var flex = child.get('visNode').getMaxWidthScaled();
|
||||
var portion = (flex / totalFlex) * myLength;
|
||||
var adjustedPortion = checkPortion(portion, index);
|
||||
var thisCenterFrac = getCenterFrac(index, centerFrac);
|
||||
|
||||
var childMin = prevBound;
|
||||
var childMax = childMin + adjustedPortion;
|
||||
var childMax = childMin + portion;
|
||||
|
||||
this.assignBoundsRecursive(child, childMin, childMax);
|
||||
this.assignBoundsRecursive(child, childMin, childMax, thisCenterFrac);
|
||||
prevBound = childMin + portion;
|
||||
}, this);
|
||||
};
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue