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

Commit

Permalink
fix issue 140 wrong arrow angle
Browse files Browse the repository at this point in the history
The steps to reproduce error:

var master = gitgraph.branch("master");
master.commit();
var branch0 = master.branch("branch0");
var branch1 = branch0.branch("branch1");
var branch2 = branch0.branch("branch2");

branch1.commit()
branch2.commit()

The arrow point from branch0 to branch2, branch3
will have vertical directions.

The cause:
When create a new commit object, it will first check parentBranch
has commit or not. If it has commit, it will push a new point
to path, so there will have a broken-line to this commit.
In the above case, the branch0 has no commit when branch1, 2
commit, so branch1, 2 will have no breakpoint in path, instead
the line will straightly draw from master to the commit.

The fix:
The check of parentCommit is empty or not is actually not needed.
We can always draw broken-line by removing the condition.
Now every path to commit will have a broken point before it, and
the direction of arrow is correct now.
Also, it will push a point to parentBranch if parentBranch has commit.
The code will generate some error path. For example, in above case,
adding a branch0.commit() after branch2.commit()
The line will have not breakpoint in path since branch0 has a point
in it already when branch1 commit.

To be check:
I think there will have some problem if we adjust the template spacing.
Since the direction of arrow is vertical or not is determined by
the relative position of parent commit and current commit.
However the direction of path is now always segmented.
This acquires more example to check the correctness.
  • Loading branch information
yodalee committed Mar 31, 2017
1 parent a6adf99 commit f3e8a4a
Showing 1 changed file with 7 additions and 13 deletions.
20 changes: 7 additions & 13 deletions src/gitgraph.js
Original file line number Diff line number Diff line change
Expand Up @@ -727,19 +727,13 @@

if (!isFirstBranch && isPathBeginning) {
this.pushPath(this.startPoint);

// Trace path from parent branch if it has commits already
if (this.parentBranch.commits.length > 0) {
this.pushPath({
x: this.startPoint.x - this.parentBranch.offsetX + this.offsetX - this.template.commit.spacingX,
y: this.startPoint.y - this.parentBranch.offsetY + this.offsetY - this.template.commit.spacingY,
type: "join"
});

var parent = _clone(this.startPoint);
parent.type = "join";
this.parentBranch.pushPath(parent);
}
// Add a path point to startpoint + offset - template spacing
// So that line will not go through commit of other branches
this.pushPath({
x: this.startPoint.x + this.offsetX - this.template.commit.spacingX,
y: this.startPoint.y + this.offsetY - this.template.commit.spacingY,
type: "join"
});
} else if (isPathBeginning) {
point.type = "start";
}
Expand Down

0 comments on commit f3e8a4a

Please sign in to comment.