mirror of
https://github.com/pcottle/learnGitBranching.git
synced 2025-06-28 00:40:07 +02:00
fiel refactor
This commit is contained in:
parent
2b308e2ae9
commit
68ff9cebea
6 changed files with 820 additions and 845 deletions
|
@ -16,84 +16,6 @@ var VisNode = Tree.VisNode;
|
|||
var VisBranch = Tree.VisBranch;
|
||||
var VisEdge = Tree.VisEdge;
|
||||
|
||||
var Visualization = Backbone.View.extend({
|
||||
initialize: function(options) {
|
||||
var _this = this;
|
||||
new Raphael(10, 10, 200, 200, function() {
|
||||
|
||||
// for some reason raphael calls this function with a predefined
|
||||
// context...
|
||||
// so switch it
|
||||
_this.paperInitialize(this, options);
|
||||
});
|
||||
},
|
||||
|
||||
paperInitialize: function(paper, options) {
|
||||
options = options || {};
|
||||
this.treeString = options.treeString;
|
||||
this.paper = paper;
|
||||
|
||||
var Main = require('../app');
|
||||
this.events = Main.getEvents();
|
||||
|
||||
this.commitCollection = new CommitCollection();
|
||||
this.branchCollection = new BranchCollection();
|
||||
|
||||
this.gitVisuals = new GitVisuals({
|
||||
commitCollection: this.commitCollection,
|
||||
branchCollection: this.branchCollection,
|
||||
paper: this.paper
|
||||
});
|
||||
|
||||
var GitEngine = require('../git').GitEngine;
|
||||
this.gitEngine = new GitEngine({
|
||||
collection: this.commitCollection,
|
||||
branches: this.branchCollection,
|
||||
gitVisuals: this.gitVisuals,
|
||||
events: this.events
|
||||
});
|
||||
this.gitEngine.init();
|
||||
this.gitVisuals.assignGitEngine(this.gitEngine);
|
||||
|
||||
this.myResize();
|
||||
$(window).on('resize', _.bind(this.myResize, this));
|
||||
this.gitVisuals.drawTreeFirstTime();
|
||||
|
||||
if (this.treeString) {
|
||||
this.gitEngine.loadTreeFromString(this.treeString);
|
||||
}
|
||||
|
||||
this.setTreeOpacity(0);
|
||||
this.fadeTreeIn();
|
||||
},
|
||||
|
||||
setTreeOpacity: function(level) {
|
||||
$(this.paper.canvas).css('opacity', 0);
|
||||
},
|
||||
|
||||
fadeTreeIn: function() {
|
||||
$(this.paper.canvas).animate({opacity: 1}, 300);
|
||||
},
|
||||
|
||||
myResize: function() {
|
||||
var smaller = 1;
|
||||
var el = this.el;
|
||||
|
||||
var left = el.offsetLeft;
|
||||
var top = el.offsetTop;
|
||||
var width = el.clientWidth - smaller;
|
||||
var height = el.clientHeight - smaller;
|
||||
|
||||
$(this.paper.canvas).css({
|
||||
left: left + 'px',
|
||||
top: top + 'px'
|
||||
});
|
||||
this.paper.setSize(width, height);
|
||||
this.gitVisuals.canvasResize(width, height);
|
||||
}
|
||||
|
||||
});
|
||||
|
||||
function GitVisuals(options) {
|
||||
this.commitCollection = options.commitCollection;
|
||||
this.branchCollection = options.branchCollection;
|
||||
|
@ -173,7 +95,7 @@ GitVisuals.prototype.initHeadBranch = function() {
|
|||
this.addBranchFromEvent(this.gitEngine.HEAD);
|
||||
};
|
||||
|
||||
GitVisuals.prototype.getScreenBounds = function() {
|
||||
GitVisuals.prototype.getScreenPadding = function() {
|
||||
// for now we return the node radius subtracted from the walls
|
||||
return {
|
||||
widthPadding: GRAPHICS.nodeRadius * 1.5,
|
||||
|
@ -185,15 +107,15 @@ GitVisuals.prototype.toScreenCoords = function(pos) {
|
|||
if (!this.paper.width) {
|
||||
throw new Error('being called too early for screen coords');
|
||||
}
|
||||
var bounds = this.getScreenBounds();
|
||||
var padding = this.getScreenPadding();
|
||||
|
||||
var shrink = function(frac, total, padding) {
|
||||
return padding + frac * (total - padding * 2);
|
||||
};
|
||||
|
||||
return {
|
||||
x: shrink(pos.x, this.paper.width, bounds.widthPadding),
|
||||
y: shrink(pos.y, this.paper.height, bounds.heightPadding)
|
||||
x: shrink(pos.x, this.paper.width, padding.widthPadding),
|
||||
y: shrink(pos.y, this.paper.height, padding.heightPadding)
|
||||
};
|
||||
};
|
||||
|
||||
|
@ -700,6 +622,4 @@ function blendHueStrings(hueStrings) {
|
|||
return 'hsb(' + String(hue) + ',' + String(totalSat) + ',' + String(totalBright) + ')';
|
||||
}
|
||||
|
||||
exports.Visualization = Visualization;
|
||||
exports.GitVisuals = GitVisuals;
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue