Repository: mermaid-js/mermaid
File: packages/mermaid/src/diagrams/git/gitGraphRenderer.js (JavaScript)

Code before:

  const keys = Object.keys(commits);
  const sortedKeys = keys.sort((a, b) => {
    return commits[a].seq - commits[b].seq;
  });

  const isParallelCommits = gitGraphConfig.parallelCommits;
  const layoutOffset = 10;
  const commitStep = 40;
  sortedKeys.forEach((key) => {
    const commit = commits[key];
    const posWithOffset = pos + layoutOffset;

    if (isParallelCommits) {
      if (!commit.parents.length) {
        pos = 0;
        if (dir === 'TB') {
          pos = 30;
        }
      } else {
        const closestParent = findClosestParent(commit.parents);
        pos =
          dir === 'TB'
            ? commitPos[closestParent].y + commitStep
            : commitPos[closestParent].x + commitStep;
      }
    }

    const y = dir === 'TB' ? posWithOffset : branchPos[commit.branch].pos;
    const x = dir === 'TB' ? branchPos[commit.branch].pos : posWithOffset;

    // Don't draw the commits now but calculate the positioning which is used by the branch lines etc.
    if (modifyGraph) {
      let typeClass;
      let commitSymbolType =
        commit.customType !== undefined && commit.customType !== ''
          ? commit.customType
          : commit.type;
      switch (commitSymbolType) {
        case commitType.NORMAL:
          typeClass = 'commit-normal';
          break;
        case commitType.REVERSE:
          typeClass = 'commit-reverse';
          break;
        case commitType.HIGHLIGHT:
          typeClass = 'commit-highlight';
          break;
        case commitType.MERGE:
          typeClass = 'commit-merge';
          break;

Review comment (suggestion):
Oh, and please swap the blocks of this `if` to avoid the negation. 


Code after:

  const keys = Object.keys(commits);
  const sortedKeys = keys.sort((a, b) => {
    return commits[a].seq - commits[b].seq;
  });

  const isParallelCommits = gitGraphConfig.parallelCommits;
  const layoutOffset = 10;
  const commitStep = 40;
  sortedKeys.forEach((key) => {
    const commit = commits[key];

    if (isParallelCommits) {
      if (commit.parents.length) {
        const closestParent = findClosestParent(commit.parents);
        pos =
          dir === 'TB'
            ? commitPos[closestParent].y + commitStep
            : commitPos[closestParent].x + commitStep;
      } else {
        pos = 0;
        if (dir === 'TB') {
          pos = 30;
        }
      }
    }

    const posWithOffset = pos + layoutOffset;
    const y = dir === 'TB' ? posWithOffset : branchPos[commit.branch].pos;
    const x = dir === 'TB' ? branchPos[commit.branch].pos : posWithOffset;

    // Don't draw the commits now but calculate the positioning which is used by the branch lines etc.
    if (modifyGraph) {
      let typeClass;
      let commitSymbolType =
        commit.customType !== undefined && commit.customType !== ''
          ? commit.customType
          : commit.type;
      switch (commitSymbolType) {
        case commitType.NORMAL:
          typeClass = 'commit-normal';
          break;
        case commitType.REVERSE:
          typeClass = 'commit-reverse';
          break;
        case commitType.HIGHLIGHT:
          typeClass = 'commit-highlight';
          break;
        case commitType.MERGE:
          typeClass = 'commit-merge';
          break;