Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bug/4912 GitGraph routing and colouring for merges and cherry-picks #4927

Merged

Conversation

guypursey
Copy link
Contributor

@guypursey guypursey commented Oct 7, 2023

📑 Summary

Fixes issues with colouring and routing of merges in GitGraph.

Resolves #4912

📏 Design Decisions

  • Changed commit variable names commit1 and commit2 to commitA and commitB respectively, to prevent confusion with seq property values (which are also numbers and used to ID the commits).
  • Refactored hasOverlappingCommits function to be easier to read and renamed it shouldRerouteArrow:
    • Used Array.some() instead of Array.filter() (should increase performance with larger graphs, if needed)
    • Swapped out Object.keys() for Object.values()
    • It takes a new argument: the name of the branch which would receive the arrow's curve and thereby causing issues for overlapping commits.
  • Introduced branch colour assignments to each conditional check for routing.
  • New e2e tests (many based on reviews by @nirname and @mathbraga)
  • Added more sample diagrams to demo folder show how the graphs should look in different situations.

📋 Tasks

Make sure you

@netlify
Copy link

netlify bot commented Oct 7, 2023

Deploy Preview for mermaid-js ready!

Name Link
🔨 Latest commit 3df7cf2
🔍 Latest deploy log https://app.netlify.com/sites/mermaid-js/deploys/65552da1a1ac44000882c681
😎 Deploy Preview https://deploy-preview-4927--mermaid-js.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify site configuration.

@codecov
Copy link

codecov bot commented Oct 7, 2023

Codecov Report

Merging #4927 (3df7cf2) into develop (e8ee5f5) will decrease coverage by 0.77%.
The diff coverage is 100.00%.

Additional details and impacted files

Impacted file tree graph

@@             Coverage Diff             @@
##           develop    #4927      +/-   ##
===========================================
- Coverage    80.13%   79.37%   -0.77%     
===========================================
  Files          164      164              
  Lines        13864    13869       +5     
  Branches       698      698              
===========================================
- Hits         11110    11008     -102     
- Misses        2604     2711     +107     
  Partials       150      150              
Flag Coverage Δ
e2e 85.28% <100.00%> (-0.97%) ⬇️
unit 42.91% <ø> (ø)

Flags with carried forward coverage won't be shown. Click here to find out more.

Files Coverage Δ
...kages/mermaid/src/diagrams/git/gitGraphRenderer.js 98.18% <100.00%> (+0.03%) ⬆️

... and 9 files with indirect coverage changes

@guypursey guypursey force-pushed the bug/4912_gitgraph-merge-routing-colouring branch from c4843e0 to 2a564f0 Compare October 7, 2023 18:25
@guypursey
Copy link
Contributor Author

E2E tests passing locally but just one test is failing remotely (other/interactive.spec).

Took the opportunity to reword some commit messages via rebase interactive and force pushed changes to retrigger test run.

@guypursey
Copy link
Contributor Author

@nirname Not sure of etiquette re requesting approval but this one is ready for review now 🙂

@nirname
Copy link
Contributor

nirname commented Oct 11, 2023

@guypursey No problem at all, ask for review as many times as needed.

I saw you have added demo page. That is good, but not enough. We also need to ensure that the following changes won't break this one. Code Coverage complains about that line you've added. Perhaps you need to add another end-2-end test on top of the existing ones. Integration tests basically make a screenshot and compare it when you do the changes. A couple of samples to cover both p1.y > p2.y and the opposite p1.y <= p2.y would be enough. Please check if this issue is reproduced for vertical orientation (TB, top-bottom) of gitGraph also.

Copy link
Contributor

@nirname nirname left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We also need to check this solution against TB graph

packages/mermaid/src/diagrams/git/gitGraphRenderer.js Outdated Show resolved Hide resolved
packages/mermaid/src/diagrams/git/gitGraphRenderer.js Outdated Show resolved Hide resolved
@guypursey guypursey force-pushed the bug/4912_gitgraph-merge-routing-colouring branch 2 times, most recently from 8e1de27 to 14d585e Compare October 12, 2023 20:39
@guypursey
Copy link
Contributor Author

guypursey commented Oct 13, 2023

@nirname @mathbraga I have made a few changes since your last reviews and updated the PR description at the top.

It looks like code coverage has now increased slightly from the develop branch since my recent changes -- I think the existing integration tests should cover what's needed anyway. When I run Cypress locally, the only changes I see seem to be what I was trying to fix. Let me know if you spot anything else though.

@mathbraga
Copy link
Contributor

Hey @guypursey, all looks good for my reviews. I think only @nirname can resolve conversations though.

@nirname
Copy link
Contributor

nirname commented Oct 15, 2023

Your code breaks something. I have faced this rendering issue

While current version works fine

gitGraph
      commit
      commit
      branch feature-001
      commit
      commit
      checkout main
      branch feature-002
      commit
      checkout feature-001
      merge feature-002

@guypursey
Copy link
Contributor Author

guypursey commented Oct 15, 2023

@nirname Good catch.

  • I've added 2x e2e tests (and updated demos) as the scenario you mentioned wasn't being tested.
  • I've removed a line of code and the condition that was causing the issue.

Ready for review 👍

@mathbraga
Copy link
Contributor

@guypursey You missed the gitGraph TB: on the first line of your second test body (test 35) for the vertical render.

@guypursey
Copy link
Contributor Author

guypursey commented Oct 17, 2023

You missed the gitGraph TB: on the first line of your second test body (test 35) for the vertical render.

Ah, thanks @mathbraga. Well spotted. I've updated that now.

In looking again, I realised I hadn't specified the commit IDs in each new test. This meant the IDs would show up in diff output as they would change between Cypress runs.

So I've now followed the practice of other graphs and added an ID for each commit 👍

@guypursey guypursey force-pushed the bug/4912_gitgraph-merge-routing-colouring branch from 7922dc9 to 39ae754 Compare October 19, 2023 07:18
@guypursey
Copy link
Contributor Author

guypursey commented Oct 19, 2023

@nirname I've just rebased this PR from develop branch to ensure coverage is still okay.

I think I've addressed your request now, so ready for review again when you have time 👍

@guypursey guypursey changed the title Bug/4912 gitgraph merge routing colouring Bug/4912 GitGraph routing and colouring for merges and cherry-picks Oct 19, 2023
Copy link
Contributor

@nirname nirname left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@guypursey Sorry for long response. I have discovered that unnecessary routing still appears in your branch, while it does not appear in current release

Expected behaviour (and current release behavior)

Current behaviour (in this branch only)

I know it seems to be minor, nevertheless users rely on the layout, and if it changes suddenly their docs may be ruined. We have measure thrice. Try this code to reproduce:

gitGraph:
  commit
  branch x
  checkout main
  commit
  checkout x
  commit
  checkout main
  merge x

Colors works as expected, by the way. I am not sure why it changes layout. May be this happens because you have changed shouldRerouteArrow function (formerly hasOverlappingCommits).

Try investigating it further.

@nirname
Copy link
Contributor

nirname commented Oct 22, 2023

We are almost there. Good to go after fixing some layout problems. Great job.

@guypursey guypursey force-pushed the bug/4912_gitgraph-merge-routing-colouring branch from 39ae754 to a8e544f Compare October 24, 2023 20:30
guypursey added a commit to guypursey/mermaid that referenced this pull request Oct 24, 2023
In these tests, a new branch is created but then a commit is made
on the main branch before the new branch gets a commit. This
important to see what happens with rerouting of arrows.

Suggested by @nirname in PR review of mermaid-js#4927.
guypursey added a commit to guypursey/mermaid that referenced this pull request Oct 26, 2023
In these tests, a new branch is created but then a commit is made
on the main branch before the new branch gets a commit. This
important to see what happens with rerouting of arrows.

Suggested by @nirname in PR review of mermaid-js#4927.
@guypursey guypursey force-pushed the bug/4912_gitgraph-merge-routing-colouring branch from abd00b4 to dc2fa29 Compare October 26, 2023 08:36
On previous rewrite, I had created new functions within the
overlapping functions but these were being recreated on each
iteration of Object.some(). I moved them outside this for
clarity and so they're not recreated each iteration.
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.
Checking if branch was same as main turned out to be redundant
for now, since there don't seem to be any cases where routing
curves into main.

This fixes issue found in review by @nirname and avoids a
situation where branching from the same commit results in
unnecessary rerouting.
Followed practice of other tests so that commit IDs are
stabilised (i.e., not randomly generated) and therefore
don't show repeatedly in Cypress diff output screenshots
In these tests, a new branch is created but then a commit is made
on the main branch before the new branch gets a commit. This
important to see what happens with rerouting of arrows.

Suggested by @nirname in PR review of mermaid-js#4927.
Hypothesised that working out which branch needed checking for
overlapping commits might be missing, so added that as a
nested ternary and passed result as new argument to rerouting
check.

If commits are found on the branch which will be getting the
curve (whichever branch is lower or more to the right of main
than the other, for now), then the arrow will be rerouted.

I may refactor in a follow-up commit and I think there's scope
to simplify the logic but this is a test for now.
My focus earlier on had been on relationship to `main` branch
so this is to ensure that we have some tests that cover
relationship between a pair of branches that doesn't
include `main`.
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.
Should stop randomised commit IDs from showing arbitrary
differences between test runs.
Wanted to avoid repetition given that the originally nested
ternaries had the same structure
Pre-commit lint hook had made the use of ternaries harder to read
than I'd originally intended so I introduced an additional
variable which explains what is being checked and keeps ternaries
from becoming obscured.
@guypursey guypursey force-pushed the bug/4912_gitgraph-merge-routing-colouring branch from 22fd12d to 57a9d73 Compare October 31, 2023 17:24
@nirname nirname added the Type: Bug / Error Something isn't working or is incorrect label Nov 13, 2023
Copy link
Member

@sidharthv96 sidharthv96 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@guypursey PR looks wonderful!

@nirname can you resolve the conversations if you're satisfied with the responses?

@nirname nirname added this pull request to the merge queue Nov 15, 2023
Merged via the queue into mermaid-js:develop with commit d7f59c1 Nov 15, 2023
18 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Type: Bug / Error Something isn't working or is incorrect
Projects
None yet
Development

Successfully merging this pull request may close these issues.

GitGraph - line routing and colour for adjacent merges
4 participants