Skip to content
This repository was archived by the owner on Jul 13, 2024. It is now read-only.

Commit 1148cf2

Browse files
committed
Merge develop into master
2 parents 0bbc8c7 + e4f3bb1 commit 1148cf2

File tree

13 files changed

+965
-185
lines changed

13 files changed

+965
-185
lines changed

bower.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "gitgraph.js",
3-
"version": "1.1.3",
3+
"version": "1.2.0",
44
"main": [ "./build/gitgraph.js", "./build/gitgraph.css" ],
55
"ignore": [
66
"**/.*"

build/gitgraph.js

Lines changed: 106 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/* ==========================================================
2-
* GitGraph v1.1.3
2+
* GitGraph v1.2.0
33
* https://github.com/nicoespeon/gitgraph.js
44
* ==========================================================
55
* Copyright (c) 2016 Nicolas CARLO (@nicoespeon) ٩(^‿^)۶
@@ -68,6 +68,28 @@
6868
return scalingFactor;
6969
}
7070

71+
/**
72+
* Returns `true` if `graph` has a vertical orientation.
73+
*
74+
* @param {GitGraph} graph
75+
* @returns {boolean}
76+
* @private
77+
*/
78+
function _isVertical ( graph ) {
79+
return (graph.orientation === "vertical" || graph.orientation === "vertical-reverse");
80+
}
81+
82+
/**
83+
* Returns `true` if `graph` has an horizontal orientation.
84+
*
85+
* @param {GitGraph} graph
86+
* @returns {boolean}
87+
* @private
88+
*/
89+
function _isHorizontal ( graph ) {
90+
return (graph.orientation === "horizontal" || graph.orientation === "horizontal-reverse");
91+
}
92+
7193
/**
7294
* GitGraph
7395
*
@@ -80,6 +102,7 @@
80102
* @param {String} [options.mode = (null|"compact")] - Display mode
81103
* @param {HTMLElement} [options.canvas] - DOM canvas (ex: document.getElementById("id"))
82104
* @param {String} [options.orientation = ("vertical-reverse"|"horizontal"|"horizontal-reverse")] - Graph orientation
105+
* @param {Boolean} [options.reverseArrow = false] - Make arrows point to ancestors if true
83106
*
84107
* @this GitGraph
85108
**/
@@ -88,16 +111,15 @@
88111
options = (typeof options === "object") ? options : {};
89112
this.elementId = (typeof options.elementId === "string") ? options.elementId : "gitGraph";
90113
this.author = (typeof options.author === "string") ? options.author : "Sergio Flores <[email protected]>";
114+
this.reverseArrow = booleanOptionOr( options.reverseArrow, false );
91115

92116
// Template management
93117
if ( (typeof options.template === "string")
94118
|| (typeof options.template === "object") ) {
95119
this.template = this.newTemplate( options.template );
96-
}
97-
else if ( options.template instanceof Template ) {
120+
} else if ( options.template instanceof Template ) {
98121
this.template = options.template;
99-
}
100-
else {
122+
} else {
101123
this.template = this.newTemplate( "metro" );
102124
}
103125

@@ -284,7 +306,7 @@
284306
* @this GitGraph
285307
**/
286308
GitGraph.prototype.render = function () {
287-
var scalingFactor = _getScale( this.context );
309+
this.scalingFactor = _getScale( this.context );
288310

289311
// Resize canvas
290312
var unscaledResolution = {
@@ -305,8 +327,8 @@
305327
this.canvas.style.width = unscaledResolution.x + "px";
306328
this.canvas.style.height = unscaledResolution.y + "px";
307329

308-
this.canvas.width = unscaledResolution.x * scalingFactor;
309-
this.canvas.height = unscaledResolution.y * scalingFactor;
330+
this.canvas.width = unscaledResolution.x * this.scalingFactor;
331+
this.canvas.height = unscaledResolution.y * this.scalingFactor;
310332

311333
// Clear All
312334
this.context.clearRect( 0, 0, this.canvas.width, this.canvas.height );
@@ -325,7 +347,7 @@
325347
}
326348

327349
// Scale the context when every transformations have been made.
328-
this.context.scale( scalingFactor, scalingFactor );
350+
this.context.scale( this.scalingFactor, this.scalingFactor );
329351

330352
// Render branches
331353
for ( var i = this.branches.length - 1, branch; !!(branch = this.branches[ i ]); i-- ) {
@@ -338,6 +360,8 @@
338360
for ( var j = 0, commit; !!(commit = this.commits[ j ]); j++ ) {
339361
commit.render();
340362
}
363+
364+
_emitEvent( this.canvas, "graph:render", { id: this.elementId } );
341365
};
342366

343367
/**
@@ -357,11 +381,9 @@
357381
* @this GitGraph
358382
**/
359383
GitGraph.prototype.applyCommits = function ( event, callbackFn ) {
360-
var scalingFactor = _getScale( this.context );
361-
362384
for ( var i = 0, commit; !!(commit = this.commits[ i ]); i++ ) {
363-
var distanceX = (commit.x + (this.offsetX + this.marginX) / scalingFactor - event.offsetX);
364-
var distanceY = (commit.y + (this.offsetY + this.marginY) / scalingFactor - event.offsetY);
385+
var distanceX = (commit.x + (this.offsetX + this.marginX) / this.scalingFactor - event.offsetX);
386+
var distanceY = (commit.y + (this.offsetY + this.marginY) / this.scalingFactor - event.offsetY);
365387
var distanceBetweenCommitCenterAndMouse = Math.sqrt( Math.pow( distanceX, 2 ) + Math.pow( distanceY, 2 ) );
366388
var isOverCommit = distanceBetweenCommitCenterAndMouse < this.template.commit.dot.size;
367389

@@ -397,31 +419,36 @@
397419
self.tooltip.style.display = "block";
398420
}
399421

400-
function emitMouseoverEvent ( commit ) {
401-
var mouseoverEventOptions = {
422+
function emitCommitEvent ( commit, event ) {
423+
var mouseEventOptions = {
402424
author: commit.author,
403425
message: commit.message,
404426
date: commit.date,
405427
sha1: commit.sha1
406428
};
407429

408-
_emitEvent( self.canvas, "commit:mouseover", mouseoverEventOptions );
430+
_emitEvent( self.canvas, "commit:" + event, mouseEventOptions );
409431
}
410432

411433
self.applyCommits( event, function ( commit, isOverCommit ) {
412434
if ( isOverCommit ) {
413-
if ( !self.template.commit.message.display ) {
435+
if ( !self.template.commit.message.display && self.template.commit.shouldDisplayTooltipsInCompactMode ) {
414436
showCommitTooltip( commit );
415437
}
416438

417-
if ( !commit.isMouseover ) {
418-
emitMouseoverEvent( commit );
439+
// Don't emit event if we already were over a commit.
440+
if ( !commit.isMouseOver ) {
441+
emitCommitEvent( commit, "mouseover" );
419442
}
420443

421444
isOut = false;
422-
commit.isMouseover = true;
445+
commit.isMouseOver = true;
423446
} else {
424-
commit.isMouseover = false;
447+
// Don't emit event if we already were out of a commit.
448+
if ( commit.isMouseOver ) {
449+
emitCommitEvent( commit, "mouseout" );
450+
}
451+
commit.isMouseOver = false;
425452
}
426453
} );
427454

@@ -587,8 +614,7 @@
587614
**/
588615
Branch.prototype.commit = function ( options ) {
589616
if ( typeof (options) === "string" ) {
590-
var message = options;
591-
options = { message: message };
617+
options = { message: options };
592618
} else if ( typeof (options) !== "object" ) {
593619
options = {};
594620
}
@@ -731,7 +757,7 @@
731757

732758
// Check integrity of target
733759
if ( targetBranch instanceof Branch === false || targetBranch === this ) {
734-
return;
760+
return this;
735761
}
736762

737763
// Merge commit
@@ -820,18 +846,29 @@
820846
* @param {String} [options.date] - Date of commit, default is now
821847
* @param {String} [options.detail] - DOM Element of detail part
822848
* @param {String} [options.sha1] - Sha1, default is a random short sha1
849+
* @param {Commit} [options.parentCommit] - Parent commit
850+
* @param {String} [options.type = ("mergeCommit"|null)] - Type of commit
851+
*
852+
* @param {String} [options.tag] - Tag of the commit
853+
* @param {String} [options.tagColor = options.color] - Specific tag color
854+
* @param {String} [options.tagFont = this.template.commit.tag.font] - Font of the tag
855+
*
823856
* @param {String} [options.dotColor = options.color] - Specific dot color
824857
* @param {Number} [options.dotSize = this.template.commit.dot.size] - Dot size
825858
* @param {Number} [options.dotStrokeWidth = this.template.commit.dot.strokeWidth] - Dot stroke width
826859
* @param {Number} [options.dotStrokeColor = this.template.commit.dot.strokeColor]
827-
* @param {Commit} [options.parentCommit] - Parent commit
860+
*
828861
* @param {String} [options.message = "He doesn't like George Michael! Boooo!"] - Commit message
829862
* @param {String} [options.messageColor = options.color] - Specific message color
863+
* @param {String} [options.messageFont = this.template.commit.message.font] - Font of the message
830864
* @param {Boolean} [options.messageDisplay = this.template.commit.message.display] - Commit message policy
831865
* @param {Boolean} [options.messageAuthorDisplay = this.template.commit.message.displayAuthor] - Commit message author policy
832866
* @param {Boolean} [options.messageBranchDisplay = this.template.commit.message.displayBranch] - Commit message author policy
833867
* @param {Boolean} [options.messageHashDisplay = this.template.commit.message.displayHash] - Commit message hash policy
834-
* @param {String} [options.type = ("mergeCommit"|null)] - Type of commit
868+
*
869+
* @param {String} [options.labelColor = options.color] - Specific label color
870+
* @param {String} [options.labelFont = this.template.branch.labelFont] - Font used for labels
871+
*
835872
* @param {commitCallback} [options.onClick] - OnClick event for the commit dot
836873
* @param {Object} [options.representedObject] - Any object which is related to this commit. Can be used in onClick or the formatter. Useful to bind the commit to external objects such as database id etc.
837874
*
@@ -970,40 +1007,64 @@
9701007
// Options
9711008
var size = this.template.arrow.size;
9721009
var color = this.template.arrow.color || this.branch.color;
1010+
var isReversed = this.parent.reverseArrow;
1011+
1012+
function rotate ( y, x ) {
1013+
var direction = (isReversed) ? -1 : 1;
1014+
return Math.atan2( direction * y, direction * x );
1015+
}
9731016

9741017
// Angles calculation
975-
var alpha = Math.atan2(
976-
this.parentCommit.y - this.y,
977-
this.parentCommit.x - this.x
978-
);
1018+
var alpha = rotate( this.parentCommit.y - this.y, this.parentCommit.x - this.x );
9791019

9801020
// Merge & Fork case
9811021
if ( this.type === "mergeCommit" || this === this.branch.commits[ 0 ] /* First commit */ ) {
982-
alpha = Math.atan2(
983-
this.template.branch.spacingY * (this.parentCommit.branch.column - this.branch.column) + this.template.commit.spacingY * (this.showLabel ? 2 : 1),
984-
this.template.branch.spacingX * (this.parentCommit.branch.column - this.branch.column) + this.template.commit.spacingX * (this.showLabel ? 2 : 1)
1022+
var deltaColumn = (this.parentCommit.branch.column - this.branch.column);
1023+
var commitSpaceDelta = (this.showLabel ? 2 : 1);
1024+
1025+
var isArrowVertical = (
1026+
isReversed
1027+
&& _isVertical( this.parent )
1028+
&& Math.abs( this.y - this.parentCommit.y ) > Math.abs( this.template.commit.spacingY )
1029+
);
1030+
var alphaX = (isArrowVertical)
1031+
? 0
1032+
: this.template.branch.spacingX * deltaColumn + this.template.commit.spacingX * commitSpaceDelta;
1033+
1034+
var isArrowHorizontal = (
1035+
isReversed
1036+
&& _isHorizontal( this.parent )
1037+
&& Math.abs( this.x - this.parentCommit.x ) > Math.abs( this.template.commit.spacingX )
9851038
);
1039+
var alphaY = (isArrowHorizontal)
1040+
? 0
1041+
: this.template.branch.spacingY * deltaColumn + this.template.commit.spacingY * commitSpaceDelta;
1042+
1043+
alpha = rotate( alphaY, alphaX );
9861044
color = this.parentCommit.branch.color;
9871045
}
9881046

9891047
var delta = Math.PI / 7; // Delta between left & right (radian)
9901048

1049+
var arrowX = (isReversed) ? this.parentCommit.x : this.x;
1050+
var arrowY = (isReversed) ? this.parentCommit.y : this.y;
1051+
9911052
// Top
9921053
var h = this.template.commit.dot.size + this.template.arrow.offset;
993-
var x1 = h * Math.cos( alpha ) + this.x;
994-
var y1 = h * Math.sin( alpha ) + this.y;
1054+
var x1 = h * Math.cos( alpha ) + arrowX;
1055+
var y1 = h * Math.sin( alpha ) + arrowY;
9951056

9961057
// Bottom left
997-
var x2 = (h + size) * Math.cos( alpha - delta ) + this.x;
998-
var y2 = (h + size) * Math.sin( alpha - delta ) + this.y;
1058+
var x2 = (h + size) * Math.cos( alpha - delta ) + arrowX;
1059+
var y2 = (h + size) * Math.sin( alpha - delta ) + arrowY;
9991060

10001061
// Bottom center
1001-
var x3 = (h + size / 2) * Math.cos( alpha ) + this.x;
1002-
var y3 = (h + size / 2) * Math.sin( alpha ) + this.y;
1062+
var x3 = (h + size / 2) * Math.cos( alpha ) + arrowX;
1063+
var y3 = (h + size / 2) * Math.sin( alpha ) + arrowY;
10031064

10041065
// Bottom right
1005-
var x4 = (h + size) * Math.cos( alpha + delta ) + this.x;
1006-
var y4 = (h + size) * Math.sin( alpha + delta ) + this.y;
1066+
var x4 = (h + size) * Math.cos( alpha + delta ) + arrowX;
1067+
var y4 = (h + size) * Math.sin( alpha + delta ) + arrowY;
10071068

10081069
this.context.beginPath();
10091070
this.context.fillStyle = color;
@@ -1039,15 +1100,16 @@
10391100
* @param {String} [options.commit.color] - Master commit color (dot & message)
10401101
* @param {String} [options.commit.dot.color] - Commit dot color
10411102
* @param {Number} [options.commit.dot.size] - Commit dot size
1042-
* @param {Number} [options.commit.dot.strokewidth] - Commit dot stroke width
1103+
* @param {Number} [options.commit.dot.strokeWidth] - Commit dot stroke width
10431104
* @param {Number} [options.commit.dot.strokeColor] - Commit dot stroke color
10441105
* @param {String} [options.commit.message.color] - Commit message color
10451106
* @param {Boolean} [options.commit.message.display] - Commit display policy
10461107
* @param {Boolean} [options.commit.message.displayAuthor] - Commit message author policy
10471108
* @param {Boolean} [options.commit.message.displayBranch] - Commit message branch policy
10481109
* @param {Boolean} [options.commit.message.displayHash] - Commit message hash policy
10491110
* @param {String} [options.commit.message.font = "normal 12pt Calibri"] - Commit message font
1050-
* @param {commitCallback} [options.commit.tooltipHTMLFormatter] - Formatter for the tooltip contents.
1111+
* @param {Boolean} [options.commit.shouldDisplayTooltipsInCompactMode] - Tooltips policy
1112+
* @param {commitCallback} [options.commit.tooltipHTMLFormatter=true] - Formatter for the tooltip contents.
10511113
*
10521114
* @this Template
10531115
**/
@@ -1094,6 +1156,7 @@
10941156
this.commit.spacingY = (typeof options.commit.spacingY === "number") ? options.commit.spacingY : 25;
10951157
this.commit.widthExtension = (typeof options.commit.widthExtension === "number") ? options.commit.widthExtension : 0;
10961158
this.commit.tooltipHTMLFormatter = options.commit.tooltipHTMLFormatter || null;
1159+
this.commit.shouldDisplayTooltipsInCompactMode = booleanOptionOr( options.commit.shouldDisplayTooltipsInCompactMode, true );
10971160

10981161
// Only one color, if null message takes branch color (full commit)
10991162
this.commit.color = options.commit.color || null;

build/gitgraph.min.js

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)