Skip to content

Commit

Permalink
GitGraph: rename overlap check to shouldRerouteArrow
Browse files Browse the repository at this point in the history
The function also now does an additional check to see
if source branch in overlap check is on main.

As we're no longer purely checking for an overlap and
the only use of this function is to reroute the arrows
to avoid running over commits, this more literal name
should be clearer.
  • Loading branch information
guypursey committed Oct 13, 2023
1 parent 86b296b commit 55b9d88
Showing 1 changed file with 9 additions and 5 deletions.
14 changes: 9 additions & 5 deletions packages/mermaid/src/diagrams/git/gitGraphRenderer.js
Original file line number Diff line number Diff line change
Expand Up @@ -341,7 +341,8 @@ const drawCommits = (svg, commits, modifyGraph) => {
* Detect if there are commits
* between commitA's x-position
* and commitB's x-position on the
* same branch as commitA
* same branch as commitA, where
* commitA isn't main
*
* @param {any} commitA
* @param {any} commitB
Expand All @@ -350,8 +351,11 @@ const drawCommits = (svg, commits, modifyGraph) => {
* If there are commits between
* commitA's x-position
* and commitB's x-position
* on the source branch, where
* source branch is not main
* return true
*/
const hasOverlappingCommits = (commitA, commitB, allCommits) => {
const shouldRerouteArrow = (commitA, commitB, allCommits) => {
const isOnSourceBranch = (x) => x.branch === commitA.branch;
const isBetweenCommits = (x) => x.seq > commitA.seq && x.seq < commitB.seq;
const sourceIsMain = commitA.branch === getConfig().gitGraph.mainBranchName;
Expand Down Expand Up @@ -395,16 +399,16 @@ const findLane = (y1, y2, depth = 0) => {
const drawArrow = (svg, commitA, commitB, allCommits) => {
const p1 = commitPos[commitA.id];
const p2 = commitPos[commitB.id];
const overlappingCommits = hasOverlappingCommits(commitA, commitB, allCommits);
// log.debug('drawArrow', p1, p2, overlappingCommits, commitA.id, commitB.id);
const arrowNeedsRerouting = shouldRerouteArrow(commitA, commitB, allCommits);
// log.debug('drawArrow', p1, p2, arrowNeedsReroute, commitA.id, commitB.id);

let arc = '';
let arc2 = '';
let radius = 0;
let offset = 0;
let colorClassNum = branchPos[commitB.branch].index;
let lineDef;
if (overlappingCommits) {
if (arrowNeedsRerouting) {
arc = 'A 10 10, 0, 0, 0,';
arc2 = 'A 10 10, 0, 0, 1,';
radius = 10;
Expand Down

0 comments on commit 55b9d88

Please sign in to comment.