GitGraph: Moved branch curve check to within reroute check fn

Based on review by @nirname. I had originally been trying
to minimise number of new arguments being passed to
rerouting check but as the branch curve check is not used
elsewhere and is part of the same rerouting check it makes
sense for them to be together.

Position information now passed to rerouting fn instead.
This commit is contained in:
Guy Pursey
2023-10-27 10:41:43 +01:00
parent 31a8e040fa
commit bf52e76a39

View File

@@ -347,6 +347,8 @@ const drawCommits = (svg, commits, modifyGraph) => {
* @param {any} commitA
* @param {any} commitB
* @param branchToGetCurve
* @param p1
* @param p2
* @param allCommits
* @returns {boolean}
* If there are commits between
@@ -356,7 +358,15 @@ const drawCommits = (svg, commits, modifyGraph) => {
* source branch is not main
* return true
*/
const shouldRerouteArrow = (commitA, commitB, branchToGetCurve, allCommits) => {
const shouldRerouteArrow = (commitA, commitB, p1, p2, allCommits) => {
const branchToGetCurve =
dir === 'TB'
? p1.x < p2.x
? commitB.branch
: commitA.branch
: p1.y < p2.y
? commitB.branch
: commitA.branch;
const isOnBranchToGetCurve = (x) => x.branch === branchToGetCurve;
const isBetweenCommits = (x) => x.seq > commitA.seq && x.seq < commitB.seq;
return Object.values(allCommits).some((commitX) => {
@@ -399,15 +409,7 @@ const findLane = (y1, y2, depth = 0) => {
const drawArrow = (svg, commitA, commitB, allCommits) => {
const p1 = commitPos[commitA.id]; // arrowStart
const p2 = commitPos[commitB.id]; // arrowEnd
const branchToGetCurve =
dir === 'TB'
? p1.x < p2.x
? commitB.branch
: commitA.branch
: p1.y < p2.y
? commitB.branch
: commitA.branch;
const arrowNeedsRerouting = shouldRerouteArrow(commitA, commitB, branchToGetCurve, allCommits);
const arrowNeedsRerouting = shouldRerouteArrow(commitA, commitB, p1, p2, allCommits);
// log.debug('drawArrow', p1, p2, arrowNeedsRerouting, commitA.id, commitB.id);
// Lower-right quadrant logic; top-left is 0,0