mirror of
https://github.com/pcottle/learnGitBranching.git
synced 2025-08-28 13:58:19 +02:00
Resolves #147 Flip trees upside down with flip
This commit is contained in:
parent
108937aad5
commit
937977f232
12 changed files with 61 additions and 35 deletions
|
@ -1,7 +1,7 @@
|
|||
var _ = require('underscore');
|
||||
var Q = require('q');
|
||||
var Backbone = require('backbone');
|
||||
var GLOBAL = require('../../util/constants').GLOBAL;
|
||||
var GlobalState = require('../../util/globalState');
|
||||
var GRAPHICS = require('../../util/constants').GRAPHICS;
|
||||
|
||||
var Animation = Backbone.Model.extend({
|
||||
|
@ -67,13 +67,13 @@ var AnimationQueue = Backbone.Model.extend({
|
|||
this.set('index', 0);
|
||||
|
||||
// set the global lock that we are animating
|
||||
GLOBAL.isAnimating = true;
|
||||
GlobalState.isAnimating = true;
|
||||
this.next();
|
||||
},
|
||||
|
||||
finish: function() {
|
||||
// release lock here
|
||||
GLOBAL.isAnimating = false;
|
||||
GlobalState.isAnimating = false;
|
||||
this.get('callback')();
|
||||
},
|
||||
|
||||
|
|
|
@ -3,7 +3,7 @@ var Q = require('q');
|
|||
var Backbone = require('backbone');
|
||||
|
||||
var GRAPHICS = require('../util/constants').GRAPHICS;
|
||||
var GLOBAL = require('../util/constants').GLOBAL;
|
||||
var GlobalState = require('../util/globalState');
|
||||
|
||||
var Collections = require('../models/collections');
|
||||
var CommitCollection = Collections.CommitCollection;
|
||||
|
@ -124,10 +124,13 @@ GitVisuals.prototype.initHeadBranch = function() {
|
|||
};
|
||||
|
||||
GitVisuals.prototype.getScreenPadding = function() {
|
||||
// if we are flipping the tree, the helper bar gets in the way
|
||||
var topFactor = (GlobalState.flipTreeY) ? 3 : 1.5;
|
||||
|
||||
// for now we return the node radius subtracted from the walls
|
||||
return {
|
||||
widthPadding: GRAPHICS.nodeRadius * 1.5,
|
||||
topHeightPadding: GRAPHICS.nodeRadius * 1.5,
|
||||
topHeightPadding: GRAPHICS.nodeRadius * topFactor,
|
||||
// we pad the bottom a lot more so the branches wont go off screen
|
||||
bottomHeightPadding: GRAPHICS.nodeRadius * 5
|
||||
};
|
||||
|
@ -180,10 +183,15 @@ GitVisuals.prototype.toScreenCoords = function(pos) {
|
|||
return paddingTop + frac * (total - paddingBelow - paddingTop);
|
||||
};
|
||||
|
||||
return {
|
||||
x: shrink(pos.x, this.paper.width, padding.widthPadding),
|
||||
y: asymShrink(pos.y, this.paper.height, padding.topHeightPadding, padding.bottomHeightPadding)
|
||||
};
|
||||
var x = shrink(pos.x, this.paper.width, padding.widthPadding);
|
||||
var y =
|
||||
asymShrink(pos.y, this.paper.height, padding.topHeightPadding, padding.bottomHeightPadding);
|
||||
|
||||
if (GlobalState.flipTreeY) {
|
||||
y = this.paper.height - y;
|
||||
}
|
||||
|
||||
return {x: x, y: y};
|
||||
};
|
||||
|
||||
GitVisuals.prototype.animateAllAttrKeys = function(keys, attr, speed, easing) {
|
||||
|
@ -782,14 +790,7 @@ GitVisuals.prototype.canvasResize = function(width, height) {
|
|||
GitVisuals.prototype.genResizeFunc = function() {
|
||||
this.resizeFunc = _.debounce(
|
||||
_.bind(function(width, height) {
|
||||
|
||||
// refresh when we are ready if we are animating som ething
|
||||
if (false && GLOBAL.isAnimating) {
|
||||
var Main = require('../app');
|
||||
Main.getEventBaton().trigger('commandSubmitted', 'refresh');
|
||||
} else {
|
||||
this.refreshTree();
|
||||
}
|
||||
this.refreshTree();
|
||||
}, this),
|
||||
200,
|
||||
true
|
||||
|
|
|
@ -3,6 +3,7 @@ var Backbone = require('backbone');
|
|||
var GRAPHICS = require('../util/constants').GRAPHICS;
|
||||
|
||||
var VisBase = require('../visuals/visBase').VisBase;
|
||||
var GlobalState = require('../util/globalState');
|
||||
|
||||
var VisEdge = VisBase.extend({
|
||||
defaults: {
|
||||
|
@ -51,6 +52,7 @@ var VisEdge = VisBase.extend({
|
|||
// is M(move abs) C (curve to) (control point 1) (control point 2) (final point)
|
||||
// the control points have to be __below__ to get the curve starting off straight.
|
||||
|
||||
var flipFactor = (GlobalState.flipTreeY) ? -1 : 1;
|
||||
var coords = function(pos) {
|
||||
return String(Math.round(pos.x)) + ',' + String(Math.round(pos.y));
|
||||
};
|
||||
|
@ -58,19 +60,19 @@ var VisEdge = VisBase.extend({
|
|||
delta = delta || GRAPHICS.curveControlPointOffset;
|
||||
return {
|
||||
x: pos.x,
|
||||
y: pos.y + delta * dir
|
||||
y: pos.y + flipFactor * delta * dir
|
||||
};
|
||||
};
|
||||
var offset2d = function(pos, x, y) {
|
||||
return {
|
||||
x: pos.x + x,
|
||||
y: pos.y + y
|
||||
y: pos.y + flipFactor * y
|
||||
};
|
||||
};
|
||||
|
||||
// first offset tail and head by radii
|
||||
tailPos = offset(tailPos, -1, this.get('tail').getRadius());
|
||||
headPos = offset(headPos, 1, this.get('head').getRadius());
|
||||
headPos = offset(headPos, 1, this.get('head').getRadius() * 1.15);
|
||||
|
||||
var str = '';
|
||||
// first move to bottom of tail
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue