-
Notifications
You must be signed in to change notification settings - Fork 369
fix issue 140 wrong arrow angle #150
fix issue 140 wrong arrow angle #150
Conversation
Thanks for helping @yodalee, that's really nice of you 👍 It sounds good, but I realized the project example doesn't illustrate these use cases. I pushed the commit on your branch so you can base your work on it: yodalee@d3723cc Unfortunately, you can also see that this fix is causing the same trouble for another use case − which was using the Our issue here is that we don't handle the case of multiple branches created from a branch that has no commit. This case should behave just like if the origin branch had commits: the line should draw an angle, going straight to the commit − see picture above. This happens because "the angle" only appears when commits of the other branches are "pushed" in Y because of the commit on the origin branch. |
Yes now there is use case, I can do more research on this problem. |
I think the problem lies in the branch line direction. In your case, the line become segment and a straight line in the empty branch case. Need to find why. |
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.
d3723cc
to
f3e8a4a
Compare
I think I found a better fix to the problem, here is the commit. The fix: To be check: |
Hi @yodalee! I tested your proposal and it works nicely. Thanks a lot for contributing 👍 |
I spoke a little too quickly. After checking issue #140 I realized that there is a regression. If you take this snippet: var gitgraph = new GitGraph({
template: "blackarrow",
});
var master = gitgraph.branch("master")
master.commit();
var branch0 = master.branch("branch0")
branch0.commit();
master.commit();
branch0.commit();
var branch1 = branch0.branch("branch1")
master.merge(branch0)
var branch2 = branch1.branch("branch2")
var branch3 = branch1.branch("branch3")
branch3.commit().commit();
branch2.commit();
branch3.commit();
branch2.commit(); The rendering is broken: I re-open the issue and will wait to fix that point before releasing it. |
Yes we need some test case to verify that this modification is correct and will not cause other problem. |
#140
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");
var branch3 = branch0.branch("branch3");
branch1.commit()
branch2.commit()
branch3.commit()
The arrow point from branch0 to branch2, branch3
will have vertical directions.
The cause:
There is a property 'isForkCommit' when drawing arrow
which if set to true, the direction of arrow will
re-calculate the vertical if difference in Y direction
is larger than Y spacing of template.
The direction of branch1 arrow is correct since
difference in Y direction is equal Y spacing of template.
The fix:
The property 'isForkCommit' seems unused.
Simply remove the property from calculation of arrow direction
can solve the issue.
However, more test on other cases are required to ensure that
removing isForkCommit property not affect other render.