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

Commit 7c2e41e

Browse files
committed
Merge develop into master
2 parents bd94c52 + 1da19f5 commit 7c2e41e

File tree

13 files changed

+460
-88
lines changed

13 files changed

+460
-88
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.2.2",
3+
"version": "1.2.3",
44
"main": [ "./build/gitgraph.js", "./build/gitgraph.css" ],
55
"ignore": [
66
"**/.*"

build/gitgraph.js

Lines changed: 100 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/* ==========================================================
2-
* GitGraph v1.2.2
2+
* GitGraph v1.2.3
33
* https://github.com/nicoespeon/gitgraph.js
44
* ==========================================================
55
* Copyright (c) 2016 Nicolas CARLO (@nicoespeon) ٩(^‿^)۶
@@ -381,9 +381,13 @@
381381
* @this GitGraph
382382
**/
383383
GitGraph.prototype.applyCommits = function ( event, callbackFn ) {
384+
// Fallback onto layerX/layerY for older versions of Firefox.
385+
var offsetX = event.offsetX || event.layerX;
386+
var offsetY = event.offsetY || event.layerY;
387+
384388
for ( var i = 0, commit; !!(commit = this.commits[ i ]); i++ ) {
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);
389+
var distanceX = (commit.x + (this.offsetX + this.marginX) / this.scalingFactor - offsetX);
390+
var distanceY = (commit.y + (this.offsetY + this.marginY) / this.scalingFactor - offsetY);
387391
var distanceBetweenCommitCenterAndMouse = Math.sqrt( Math.pow( distanceX, 2 ) + Math.pow( distanceY, 2 ) );
388392
var isOverCommit = distanceBetweenCommitCenterAndMouse < this.template.commit.dot.size;
389393

@@ -487,7 +491,8 @@
487491
*
488492
* @param {Object} options - Options of branch
489493
* @param {GitGraph} options.parent - GitGraph constructor
490-
* @param {Branch} [options.parentBranch] - Parent branch
494+
* @param {Branch} [options.parentBranch = options.parentCommit.branch] - Parent branch
495+
* @param {Commit} [options.parentCommit = options.parentBranch.commits.slice(-1)[0]] - Parent commit
491496
* @param {String} [options.name = "no-name"] - Branch name
492497
*
493498
* @this Branch
@@ -501,7 +506,22 @@
501506
// Options
502507
options = (typeof options === "object") ? options : {};
503508
this.parent = options.parent;
504-
this.parentBranch = options.parentBranch;
509+
if ( options.parentCommit && options.parentBranch ) {
510+
if ( options.parentCommit.branch !== options.parentBranch ) {
511+
return;
512+
}
513+
this.parentCommit = options.parentCommit;
514+
this.parentBranch = options.parentBranch;
515+
} else if ( options.parentCommit ) {
516+
this.parentCommit = options.parentCommit;
517+
this.parentBranch = options.parentCommit.branch;
518+
} else if ( options.parentBranch ) {
519+
this.parentCommit = options.parentBranch.commits.slice( -1 )[ 0 ];
520+
this.parentBranch = options.parentBranch;
521+
} else {
522+
this.parentCommit = null;
523+
this.parentBranch = null;
524+
}
505525
this.name = (typeof options.name === "string") ? options.name : "no-name";
506526
this.context = this.parent.context;
507527
this.template = this.parent.template;
@@ -530,6 +550,25 @@
530550
this.offsetX = this.column * this.spacingX;
531551
this.offsetY = this.column * this.spacingY;
532552

553+
// Add start point
554+
if (this.parentBranch) {
555+
if ( this.parentCommit === this.parentBranch.commits.slice( -1 )[ 0 ] ) {
556+
this.startPoint = {
557+
x: this.parentBranch.offsetX - this.parent.commitOffsetX + this.template.commit.spacingX,
558+
y: this.parentBranch.offsetY - this.parent.commitOffsetY + this.template.commit.spacingY,
559+
type: "start"
560+
};
561+
} else {
562+
this.startPoint = {
563+
x: this.parentCommit.x,
564+
y: this.parentCommit.y,
565+
type: "start"
566+
};
567+
}
568+
} else {
569+
this.startPoint = null;
570+
}
571+
533572
var columnIndex = (this.column % this.template.colors.length);
534573
this.color = options.color || this.template.branch.color || this.template.colors[ columnIndex ];
535574

@@ -676,11 +715,11 @@
676715

677716
// Fork case: Parent commit from parent branch
678717
if ( options.parentCommit instanceof Commit === false && this.parentBranch instanceof Branch ) {
679-
options.parentCommit = this.parentBranch.commits.slice( -1 )[ 0 ];
718+
options.parentCommit = this.parentCommit;
680719
}
681720

682721
// First commit
683-
var isFirstBranch = options.parentCommit instanceof Commit;
722+
var isFirstBranch = !( options.parentCommit instanceof Commit );
684723
var isPathBeginning = this.path.length === 0;
685724

686725
options.showLabel = (isPathBeginning && this.showLabel) ? true : false;
@@ -700,21 +739,26 @@
700739
type: "join"
701740
};
702741

703-
if ( isFirstBranch && isPathBeginning ) {
704-
var parent = {
705-
x: commit.parentCommit.branch.offsetX - this.parent.commitOffsetX + this.template.commit.spacingX,
706-
y: commit.parentCommit.branch.offsetY - this.parent.commitOffsetY + this.template.commit.spacingY,
707-
type: "start"
708-
};
709-
this.path.push( JSON.parse( JSON.stringify( parent ) ) ); // Elegant way for cloning an object
742+
if ( !isFirstBranch && isPathBeginning ) {
743+
// Start point on parent branch
744+
this.pushPath( this.startPoint );
745+
// Move to this branch
746+
this.pushPath( {
747+
x: this.startPoint.x - this.parentBranch.offsetX + this.offsetX - this.template.commit.spacingX,
748+
y: this.startPoint.y - this.parentBranch.offsetY + this.offsetY - this.template.commit.spacingY,
749+
type: "join"
750+
} );
751+
752+
// Extend parent branch
753+
var parent = JSON.parse( JSON.stringify( this.startPoint ) ); // Elegant way for cloning an object
710754
parent.type = "join";
711-
this.parentBranch.path.push( parent );
755+
this.parentBranch.pushPath( parent );
712756
} else if ( isPathBeginning ) {
713757
point.type = "start";
714758
}
715759

716760
// Increment commitOffset for next commit position
717-
this.path.push( point );
761+
this.pushPath( point );
718762

719763
this.parent.commitOffsetX += this.template.commit.spacingX * (options.showLabel ? 2 : 1);
720764
this.parent.commitOffsetY += this.template.commit.spacingY * (options.showLabel ? 2 : 1);
@@ -790,17 +834,17 @@
790834
y: this.offsetY + this.template.commit.spacingY * (targetCommit.showLabel ? 3 : 2) - this.parent.commitOffsetY,
791835
type: "join"
792836
};
793-
this.path.push( JSON.parse( JSON.stringify( endOfBranch ) ) ); // Elegant way for cloning an object
837+
this.pushPath( JSON.parse( JSON.stringify( endOfBranch ) ) ); // Elegant way for cloning an object
794838

795839
var mergeCommit = {
796840
x: targetCommit.x,
797841
y: targetCommit.y,
798842
type: "end"
799843
};
800-
this.path.push( mergeCommit );
844+
this.pushPath( mergeCommit );
801845

802846
endOfBranch.type = "start";
803-
this.path.push( endOfBranch ); // End of branch for future commits
847+
this.pushPath( endOfBranch ); // End of branch for future commits
804848

805849
// Auto-render
806850
this.parent.render();
@@ -836,6 +880,37 @@
836880
}
837881
};
838882

883+
/**
884+
* Push a new point to path.
885+
* This method will combine duplicate points and reject reversed points.
886+
*
887+
* @this Branch
888+
*/
889+
Branch.prototype.pushPath = function (point) {
890+
var lastPoint = this.path.slice( -1 )[ 0 ];
891+
if ( !lastPoint ) {
892+
this.path.push( point );
893+
} else if ( lastPoint.x === point.x && lastPoint.y === point.y ) {
894+
if ( lastPoint.type !== "start" && point.type === "end" ) {
895+
lastPoint.type = "end";
896+
} else if ( point.type === "join" ) {
897+
898+
} else {
899+
this.path.push( point );
900+
}
901+
} else {
902+
if ( point.type === "join" ) {
903+
if ( ( point.x - lastPoint.x ) * this.template.commit.spacingX < 0 ) {
904+
this.path.push( point );
905+
} else if ( ( point.y - lastPoint.y ) * this.template.commit.spacingY < 0 ) {
906+
this.path.push( point );
907+
}
908+
} else {
909+
this.path.push( point );
910+
}
911+
}
912+
};
913+
839914
// --------------------------------------------------------------------
840915
// ----------------------- Commit ------------------------
841916
// --------------------------------------------------------------------
@@ -1036,6 +1111,9 @@
10361111
isReversed
10371112
&& _isVertical( this.parent )
10381113
&& Math.abs( this.y - this.parentCommit.y ) > Math.abs( this.template.commit.spacingY )
1114+
) || (
1115+
_isVertical( this.parent )
1116+
&& commitSpaceDelta > 1
10391117
);
10401118
var alphaX = (isArrowVertical)
10411119
? 0
@@ -1045,6 +1123,9 @@
10451123
isReversed
10461124
&& _isHorizontal( this.parent )
10471125
&& Math.abs( this.x - this.parentCommit.x ) > Math.abs( this.template.commit.spacingX )
1126+
) || (
1127+
_isHorizontal( this.parent )
1128+
&& commitSpaceDelta > 1
10481129
);
10491130
var alphaY = (isArrowHorizontal)
10501131
? 0

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)