nice hue blending and cursor focus blur

This commit is contained in:
Peter Cottle 2012-10-12 15:52:07 -07:00
parent ea6844ae04
commit bca3e1d537
5 changed files with 138 additions and 17 deletions

View file

@ -18,7 +18,11 @@ var CommandPromptView = Backbone.View.extend({
this.blur(); this.blur();
}, this)); }, this));
// hacky timeout focus TODO events.on('processCommandFromEvent', _.bind(
this.addToCollection, this
));
// hacky timeout focus
setTimeout(_.bind(function() { setTimeout(_.bind(function() {
this.focus(); this.focus();
}, this), 100); }, this), 100);
@ -26,7 +30,9 @@ var CommandPromptView = Backbone.View.extend({
events: { events: {
'keydown #commandTextField': 'onKey', 'keydown #commandTextField': 'onKey',
'keyup #commandTextField': 'onKeyUp' 'keyup #commandTextField': 'onKeyUp',
'blur #commandTextField': 'hideCursor',
'focus #commandTextField': 'showCursor'
}, },
blur: function() { blur: function() {
@ -35,8 +41,19 @@ var CommandPromptView = Backbone.View.extend({
focus: function() { focus: function() {
this.$('#commandTextField').focus(); this.$('#commandTextField').focus();
// we now our cursor is there so... this.showCursor();
$(this.commandCursor).toggleClass('shown', true); },
hideCursor: function() {
this.toggleCursor(false);
},
showCursor: function() {
this.toggleCursor(true);
},
toggleCursor: function(state) {
$(this.commandCursor).toggleClass('shown', state);
}, },
onKey: function(e) { onKey: function(e) {

View file

@ -693,9 +693,9 @@ GitEngine.prototype.merge = function(targetSource, currentLocation) {
if (this.isUpstreamOf(currentLocation, targetSource)) { if (this.isUpstreamOf(currentLocation, targetSource)) {
// just set the target of this current location to the source // just set the target of this current location to the source
this.setLocationTarget(currentLocation, this.getCommitFromRef(targetSource)); this.setLocationTarget(currentLocation, this.getCommitFromRef(targetSource));
throw new CommandResult({ // get fresh animation to happen
msg: 'Fast-forwarding...' this.command.setResult('Fast-forwarding...');
}); return;
} }
// now the part of making a merge commit // now the part of making a merge commit
@ -882,6 +882,26 @@ GitEngine.prototype.dispatch = function(command, callback) {
this.animationQueue.start(); this.animationQueue.start();
}; };
GitEngine.prototype.showStarter = function() {
if (this.generalArgs.length > 1) {
throw new GitError({
msg: 'git show with more than 1 argument does not make sense'
});
}
if (this.generalArgs.length == 0) {
this.generalArgs.push('HEAD');
}
this.show(this.generalArgs[0]);
};
GitEngine.prototype.show = function(ref) {
var commit = this.getCommitFromRef(ref);
throw new CommandResult({
msg: commit.getShowEntry()
});
};
GitEngine.prototype.logStarter = function() { GitEngine.prototype.logStarter = function() {
if (this.generalArgs.length > 1) { if (this.generalArgs.length > 1) {
throw new GitError({ throw new GitError({
@ -1032,6 +1052,19 @@ var Commit = Backbone.Model.extend({
].join('\n' ) + '\n'; ].join('\n' ) + '\n';
}, },
getShowEntry: function() {
// same deal as above, show log entry and some fake changes
return [
this.getLogEntry(),
'diff --git a/bigGameResults.html b/bigGameResults.html',
'--- bigGameResults.html',
'+++ bigGameResults.html',
'@@ 13,27 @@ Winner, Score',
'- Stanfurd, 14-7',
'+ Cal, 21-14',
].join('\n') + '\n';
},
validateAtInit: function() { validateAtInit: function() {
if (!this.get('id')) { if (!this.get('id')) {
this.set('id', uniqueId('C')); this.set('id', uniqueId('C'));

View file

@ -37,6 +37,8 @@ var VisBranch = Backbone.Model.extend({
initialize: function() { initialize: function() {
this.validateAtInit(); this.validateAtInit();
this.get('branch').set('visBranch', this);
var id = this.get('branch').get('id'); var id = this.get('branch').get('id');
if (id == 'HEAD') { if (id == 'HEAD') {
@ -214,7 +216,7 @@ var VisBranch = Backbone.Model.extend({
var totalNum = this.getBranchStackLength(); var totalNum = this.getBranchStackLength();
return { return {
w: textSize.w + vPad * 2, w: textSize.w + vPad * 2,
h: textSize.h * totalNum + hPad * 2 h: textSize.h * totalNum * 1.1 + hPad * 2
}; };
}, },
@ -236,9 +238,33 @@ var VisBranch = Backbone.Model.extend({
}, },
getFill: function() { getFill: function() {
// in the easy case, just return your own fill // in the easy case, just return your own fill if you are:
// TODO check // - the HEAD ref
return this.get('fill'); // - by yourself (length of 1)
// - part of a multi branch, but your thing is hidden
if (this.get('isHead') ||
this.getBranchStackLength() == 1 ||
this.getBranchStackIndex() != 0) {
return this.get('fill');
}
// woof. now it's hard, we need to blend hues...
var myArray = this.getBranchStackArray();
var hueStrings = [];
_.each(this.getBranchStackArray(), function(branchWrapper) {
var fill = branchWrapper.obj.get('visBranch').get('fill');
if (fill.slice(0,3) !== 'hsb') {
// crap. convert to a hsb
var color = Raphael.color(fill);
fill = 'hsb(' + String(color.h) + ',' + String(color.s);
fill = fill + ',' + String(color.l) + ')';
}
hueStrings.push(fill);
});
return blendHueStrings(hueStrings);
}, },
genGraphics: function(paper) { genGraphics: function(paper) {
@ -320,11 +346,13 @@ var VisBranch = Backbone.Model.extend({
y: rectPos.y, y: rectPos.y,
width: rectSize.w, width: rectSize.w,
height: rectSize.h, height: rectSize.h,
opacity: nonTextOpacity opacity: nonTextOpacity,
fill: this.getFill(),
}, },
arrow: { arrow: {
path: arrowPath, path: arrowPath,
opacity: nonTextOpacity opacity: nonTextOpacity,
fill: this.getFill()
} }
}; };
}, },
@ -537,6 +565,15 @@ var VisNode = Backbone.Model.extend({
} }
}, },
attachClickHandlers: function() {
var commandStr = 'git show ' + this.get('commit').get('id');
_.each([this.get('circle'), this.get('text')], function(rObj) {
rObj.click(function() {
events.trigger('processCommandFromEvent', commandStr);
});
});
},
genGraphics: function(paper) { genGraphics: function(paper) {
var pos = this.getScreenCoords(); var pos = this.getScreenCoords();
var textPos = this.getTextScreenCoords(); var textPos = this.getTextScreenCoords();
@ -554,6 +591,8 @@ var VisNode = Backbone.Model.extend({
this.set('circle', circle); this.set('circle', circle);
this.set('text', text); this.set('text', text);
this.attachClickHandlers();
} }
}); });

View file

@ -283,7 +283,6 @@ GitVisuals.prototype.addBranch = function(branch) {
var visBranch = new VisBranch({ var visBranch = new VisBranch({
branch: branch branch: branch
}); });
branch.set('visBranch', visBranch);
this.visBranchCollection.add(visBranch); this.visBranchCollection.add(visBranch);
if (this.paperReady) { if (this.paperReady) {
@ -424,6 +423,41 @@ GitVisuals.prototype.drawTreeFirstTime = function() {
/************************ /************************
* Random util functions, adapted from liquidGraph * Random util functions, adapted from liquidGraph
***********************/ ***********************/
function blendHueStrings(hueStrings) {
// assumes a sat of 0.7 and brightness of 1
var x = 0;
var y = 0;
var totalSat = 0;
var totalBright = 0;
var length = hueStrings.length;
_.each(hueStrings, function(hueString) {
var exploded = hueString.split('(')[1];
exploded = exploded.split(')')[0];
exploded = exploded.split(',');
totalSat += parseFloat(exploded[1]);
totalBright += parseFloat(exploded[2]);
var hue = parseFloat(exploded[0]);
var angle = hue * Math.PI * 2;
x += Math.cos(angle);
y += Math.sin(angle);
});
x = x / length;
y = y / length;
totalSat = totalSat / length;
totalBright = totalBright / length;
var hue = Math.atan2(y, x) / (Math.PI * 2);
if (hue < 0) {
hue = hue + 1;
}
return 'hsb(' + String(hue) + ',' + String(totalSat) + ',' + String(totalBright) + ')';
}
function constructPathStringFromCoords(points,wantsToClose) { function constructPathStringFromCoords(points,wantsToClose) {
var pathString = "M" + String(Math.round(points[0].x)) + "," + String(Math.round(points[0].y)); var pathString = "M" + String(Math.round(points[0].x)) + "," + String(Math.round(points[0].y));
var lp = points[0]; var lp = points[0];

View file

@ -12,7 +12,7 @@ ALSO other big things:
- Color on branch edges?? - Color on branch edges??
Big Graphic things: Big Graphic things:
~~~~~~~~~~~~~~~~~~~~~~~~~~ ~~~~~~~~~~~~~~~~~~~~~~~~~
- colored branch edges. basically - colored branch edges. basically
- node rings, really think we should do it - node rings, really think we should do it
- When you are rebasing and you hit the bottom, all the nodes go in the wrong spot... - When you are rebasing and you hit the bottom, all the nodes go in the wrong spot...
@ -28,8 +28,6 @@ Medium things:
Small things to implement: Small things to implement:
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
- Git show
- Git show when you click on a node (or the text technically)
Bugs to fix: Bugs to fix: