-
-
Notifications
You must be signed in to change notification settings - Fork 7.5k
fix(gitGraph): honor showBranches config to hide branch lines and labels (#6535) #6554
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
base: develop
Are you sure you want to change the base?
fix(gitGraph): honor showBranches config to hide branch lines and labels (#6535) #6554
Conversation
|
✅ Deploy Preview for mermaid-js ready!
To edit notification comments on pull requests, go to your Netlify site configuration. |
commit: |
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## develop #6554 +/- ##
==========================================
- Coverage 3.87% 3.87% -0.01%
==========================================
Files 413 412 -1
Lines 43216 43220 +4
Branches 665 665
==========================================
Hits 1675 1675
- Misses 41541 41545 +4
Flags with carried forward coverage won't be shown. Click here to find out more.
🚀 New features to boost your workflow:
|
The latest updates on your projects. Learn more about Argos notifications ↗︎
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
mermaid/packages/mermaid/src/diagrams/git/gitGraphRenderer.ts
Lines 928 to 930 in c8daf9a
if (DEFAULT_GITGRAPH_CONFIG.showBranches) { | |
drawBranches(diagram, branches); | |
} |
There is already a similar check happening here, but in both cases, DEFAULT_GITGRAPH_CONFIG
is used, which is a misleading name, and won't be updated based on the code in the diagram, as it is only initialised on load.
The proper fix would be to also update the config before rendering, by calling getConfig once inside draw
function, after clear.
Is there anything blocking us from moving the position calculations inside the drawBranches function?
Hello @sidharthv96 I've made the requested updates. The configuration is now dynamically fetched within the draw() function, and the position calculations for branches have been moved to the drawBranches() function for more accurate rendering. Please let me know if any other adjustments are needed |
@@ -812,9 +812,11 @@ const drawArrows = ( | |||
|
|||
const drawBranches = ( | |||
svg: d3.Selection<d3.BaseType, unknown, HTMLElement, any>, | |||
branches: { name: string }[] | |||
branches: { name: string }[], | |||
DEFAULT_GITGRAPH_CONFIG: any |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please use variable names matching our convention.
There will be lots of changed lines, but that's okay.
DEFAULT_GITGRAPH_CONFIG: any | |
config: MermaidConfig['gitGraph'] |
const DEFAULT_CONFIG = getConfig(); | ||
const DEFAULT_GITGRAPH_CONFIG = DEFAULT_CONFIG?.gitGraph; | ||
if (!DEFAULT_GITGRAPH_CONFIG) { | ||
throw new Error('GitGraph config not found'); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As this is not the default config, using this name is misleading. You can use config
or gitGraphConfig
.
branches.forEach((branch, index) => { | ||
const labelElement = drawText(branch.name); | ||
const g = diagram.append('g'); | ||
const branchLabel = g.insert('g').attr('class', 'branchLabel'); | ||
const label = branchLabel.insert('g').attr('class', 'label branch-label'); | ||
label.node()?.appendChild(labelElement); | ||
const bbox = labelElement.getBBox(); | ||
let bbox: DOMRect = { | ||
x: 0, | ||
y: 0, | ||
width: 0, | ||
height: 0, | ||
top: 0, | ||
right: 0, | ||
bottom: 0, | ||
left: 0, | ||
toJSON: () => '', | ||
}; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is not moved inside drawBranches
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hi, I’ve moved the branch label creation inside the drawBranches function as intended. Could you please clarify your suggestion? Thanks in advance
📑 Summary
When using
%%{ init: { "gitGraph": { "showBranches": false } } }%%
, branch lines and labels still rendered, even though they should be hidden.before :



after:
Resolves #6535
📏 Design Decisions
This PR wraps both:
drawBranches()
callWe also ensure
setBranchPosition()
still runs, sobranchPos
is correctly calculated even when branches are hidden (important for commit layout).📋 Tasks
Make sure you
MERMAID_RELEASE_VERSION
is used for all new features.pnpm changeset
and following the prompts. Changesets that add features should beminor
and those that fix bugs should bepatch
. Please prefix changeset messages withfeat:
,fix:
, orchore:
.