mermaid-js / mermaid

Generation of diagrams like flowcharts or sequence diagrams from text in a similar manner as markdown
https://mermaid.js.org
MIT License
72.08k stars 6.54k forks source link

gitGraph rendering breaks chronology #4838

Open moedn opened 1 year ago

moedn commented 1 year ago

Description

First of all: thanks for this amazing project! I use mermaid a lot :)

I'm trying to visualize the branch management for an open source MRI project, but the rendering has a glitch after a certain point (see code samples below)

Steps to reproduce

  1. use the code sample before break from below
  2. everything looks good
  3. use the complete code sample
  4. BUG: the commit working on MDR in FORK-v1.0-MDR comes before minor design changes for MDR in v1-rc, but appears after the merge in the rendered image

Screenshots

before break:

image

complete:

image

Code Sample

complete code sample:

gitGraph
   commit id:"initial commit"
   commit id:"work on first release"
   commit id:"design freeze from here"
   branch v1-rc
   checkout v1-rc
   commit id:"bugfix 1"
   commit id:"bigfix 2" tag:"v1.0.1"
   branch FORK-v1.0-MDR
   checkout FORK-v1.0-MDR
   commit id:"working on MDR"
   checkout v1-rc
   commit id:"minor design changes for MDR" tag:"v1.0.2"
   checkout FORK-v1.0-MDR
   merge v1-rc
   checkout main
   commit id:"new feature for v1.1…"
   checkout FORK-v1.0-MDR
   commit id:"working on MDR"
   commit id:"finishing MDR"
   branch v1.0-MDR
   checkout v1.0-MDR
   commit id:"brush up release" tag:"v1.0.2-MDR"
   checkout v1-rc
   commit id:"bugfix without MDR"
   checkout main
   commit id:"work on v1.1"

code sample until break

```mermaid
gitGraph
   commit id:"initial commit"
   commit id:"work on first release"
   commit id:"design freeze from here"
   branch v1-rc
   checkout v1-rc
   commit id:"bugfix 1"
   commit id:"bigfix 2" tag:"v1.0.1"
   branch FORK-v1.0-MDR
   checkout FORK-v1.0-MDR
   commit id:"working on MDR"
   checkout v1-rc
   commit id:"minor design changes for MDR" tag:"v1.0.2"
   checkout FORK-v1.0-MDR
   merge v1-rc
   checkout main
   commit id:"new feature for v1.1…"


### Setup

- Mermaid version: `10.3.1`
- Browser and Version: Brave v1.57.62 Chromium: 116.0.5845.180 (Official Build) (64-bit) (but rendered in GitLab.com [here](https://gitlab.com/osii/admin/-/issues/1#note_1553323117))
SavvyShah commented 1 year ago

I was just taking a look here and I found that commit id "working on MDR" is repeated. Should this be considered a bug then?

moedn commented 1 year ago

jepp, that seems to be the issue :+1:

if I replace the ID with "further work on MDR", it renders correctly. otherwise mermaid doesn't seem to have an issue with repetitive commit IDs

Adithya31101 commented 1 year ago

I have used mermaid, but never really looked into the code base. But I have experience with D3 and SVGs in general. Can I pick this up, and give it a try?

PS: this is my first shot at open source contribution

guypursey commented 1 year ago

Is this actually the bug that needs addressing? Or is it more that Mermaid should have an issue with repeated/duplication commit IDs?

Commit IDs should be unique generally, of course. But I think the "cherry-pick" feature in Mermaid would mean the IDs need to be unique for that feature to work.

With unique IDs:

gitGraph
    commit
    branch develop
    checkout develop
    commit id:"hello"
    commit id:"world"
    checkout main
    commit
    cherry-pick id:"hello"
gitGraph
    commit
    branch develop
    checkout develop
    commit id:"hello"
    commit id:"world"
    checkout main
    commit
    cherry-pick id:"hello"

With duplicate IDs:

gitGraph
    commit
    branch develop
    checkout develop
    commit id:"hello"
    commit id:"hello"
    checkout main
    commit
    cherry-pick id:"hello"

[NOTE: 2 commits now become 1]

gitGraph
    commit
    branch develop
    checkout develop
    commit id:"hello"
    commit id:"hello"
    checkout main
    commit
    cherry-pick id:"hello"
guypursey commented 1 year ago

Perhaps there's a feature request underlying this -- to have a commit "message:" parameter in the syntax too, which can be duplicated, while IDs remain unique