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

fix: Prevent Legend Labels from Overlapping Diagram Elements in Journey Diagrams #6274

Open
wants to merge 21 commits into
base: develop
Choose a base branch
from

Conversation

Shahir-47
Copy link

@Shahir-47 Shahir-47 commented Feb 13, 2025

📑 Summary

Fixed an issue where long legend labels in Journey diagrams could overlap with the diagram elements. In addition, we've added a new journey theme variable, maxLabelWidth, which allows users to control the maximum width of actor labels. This variable is configured as follows:

maxLabelWidth:
  description: Maximum width of actor labels
  type: integer
  default: 360
  minimum: 240
  maximum: 480

By tracking the maximum width of legend text elements, we now ensure proper spacing between the legend and the diagram content. This update also improves text-wrapping by:

  • Breaking a long word with a hyphen if it exceeds the max width, then resuming the remaining word on the next line.
  • Starting a new line without a hyphen if the break occurs at whitespace.

Resolves #5955

📏 Design Decisions

The implementation works by:

  1. Tracking the maximum width of legend text elements during the actor legend drawing phase.
  2. Using this width to calculate the appropriate left margin for the diagram elements.
  3. Introducing the maxLabelWidth theme variable to let users set how long each label line should be.
  4. Implementing word-wrapping behavior:
    • Hyphenation: If a word exceeds the line length, a hyphen is added at the break and the remaining text resumes on the next line.
    • Whitespace Wrapping: If the break occurs at a space, the new word starts on the next line without a hyphen.
  5. Adding end-to-end tests to verify:
    • The proper wrapping behavior that adheres to the maxLabelWidth constraint.
    • That no line exceeds the specified max width, thereby maintaining consistent spacing between the legend and diagram.
    • The correct margin is maintained between the longest legend line and the diagram elements.

Before:

image

After:

image

📋 Tasks

Shahir-47 and others added 4 commits February 5, 2025 19:27
Co-authored-by: Pranav Mishra <mishrap@dickinson.edu>
Co-authored-by: Shahir Ahmed <ahmeds@dickinson.edu>
Co-authored-by: Pranav Mishra <mishrap@dickinson.edu>
Co-authored-by: Pranav Mishra <mishrap@dickinson.edu>
Copy link

changeset-bot bot commented Feb 13, 2025

⚠️ No Changeset found

Latest commit: a2f0d8e

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

@github-actions github-actions bot added the Type: Bug / Error Something isn't working or is incorrect label Feb 13, 2025
Copy link

netlify bot commented Feb 13, 2025

Deploy Preview for mermaid-js ready!

Name Link
🔨 Latest commit a2f0d8e
🔍 Latest deploy log https://app.netlify.com/sites/mermaid-js/deploys/67c0cc179a1ea40008456d7b
😎 Deploy Preview https://deploy-preview-6274--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.

Copy link

pkg-pr-new bot commented Feb 13, 2025

Open in Stackblitz

npm i https://pkg.pr.new/mermaid-js/mermaid@6274
npm i https://pkg.pr.new/mermaid-js/mermaid/@mermaid-js/mermaid-zenuml@6274
npm i https://pkg.pr.new/mermaid-js/mermaid/@mermaid-js/layout-elk@6274
npm i https://pkg.pr.new/mermaid-js/mermaid/@mermaid-js/parser@6274

commit: a2f0d8e

Copy link

codecov bot commented Feb 13, 2025

Codecov Report

Attention: Patch coverage is 0% with 56 lines in your changes missing coverage. Please review.

Project coverage is 3.88%. Comparing base (00a8dc4) to head (a2f0d8e).

Files with missing lines Patch % Lines
...rmaid/src/diagrams/user-journey/journeyRenderer.ts 0.00% 56 Missing ⚠️
Additional details and impacted files

Impacted file tree graph

@@            Coverage Diff             @@
##           develop   #6274      +/-   ##
==========================================
- Coverage     3.88%   3.88%   -0.01%     
==========================================
  Files          399     398       -1     
  Lines        42055   42084      +29     
  Branches       638     638              
==========================================
  Hits          1635    1635              
- Misses       40420   40449      +29     
Flag Coverage Δ
unit 3.88% <0.00%> (-0.01%) ⬇️

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

Files with missing lines Coverage Δ
packages/mermaid/src/config.type.ts 100.00% <ø> (ø)
...rmaid/src/diagrams/user-journey/journeyRenderer.ts 0.38% <0.00%> (-0.08%) ⬇️

... and 1 file with indirect coverage changes

@Shahir-47
Copy link
Author

Hey @sidharthv96,

@pranavm2109 and I have fixed the issue with overlapping legend labels in Journey diagrams #5955. The fix ensures proper spacing by tracking the maximum width of legend text elements during the actor legend drawing phase and using this width to adjust the left margin for the diagram elements. We’ve also added E2E tests to verify that spacing remains correct for both normal and long labels.

All GitHub tests and CICD checks are passing, and this is ready to be merged. Full details are in the PR description—let us know if you have any questions or feedback!

…ations

Co-authored-by: pranavm2109 <mishrap@dickinson.edu>
@Shahir-47 Shahir-47 changed the title fix: Prevent legend text overlap in Journey diagrams Prevent legend text overlap in Journey diagrams Feb 13, 2025
@Shahir-47 Shahir-47 changed the title Prevent legend text overlap in Journey diagrams fix: Prevent Legend Labels from Overlapping Diagram Elements in Journey Diagrams Feb 13, 2025
@@ -84,31 +90,32 @@ export const draw = function (text, id, version, diagObj) {
});

drawActorLegend(diagram);
bounds.insert(0, 0, LEFT_MARGIN, Object.keys(actors).length * 50);
leftMargin = conf.leftMargin + maxWidth - 22.328125;
Copy link
Member

Choose a reason for hiding this comment

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

What is 22.328125, please avoid magic numbers.

Comment on lines 106 to 124
cy.then(() => {
renderGraph(
`journey
title Web hook life cycle
section Darkoob
Make preBuilt:5: Darkoob user
register slug : 5: Darkoob userf deliberately increasing the size of this label to check if distance between legend and diagram is maintained
Map slug to a Prebuilt Job:5: Darkoob user
section External Service
set Darkoob slug as hook for an Event : 5 : admin Exjjjnjjjj qwerty
listen to the events : 5 : External Service
call darkoob endpoint : 5 : External Service
section Darkoob
check for inputs : 5 : DarkoobAPI
run the prebuilt job : 5 : DarkoobAPI
`,
{ journey: { useMaxWidth: true } }
);
});
Copy link
Member

Choose a reason for hiding this comment

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

Why is the cy.then required, when it's not used in other functions?

Copy link

argos-ci bot commented Feb 15, 2025

The latest updates on your projects. Learn more about Argos notifications ↗︎

Build Status Details Updated (UTC)
default (Inspect) ⚠️ Changes detected (Review) 4 added Feb 27, 2025, 8:43 PM

Comment on lines 45 to 49
const textElement = svgDraw.drawText(diagram, labelData);
const textLength = textElement.node().getBBox().width;
if (textLength > maxWidth) {
maxWidth = textLength;
}
Copy link
Member

Choose a reason for hiding this comment

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

Not blocker: We should keep this dynamic width part, but should we split the text into more lines, if it's longer that a longer max limit?

Shahir-47 and others added 13 commits February 18, 2025 16:05
Co-authored-by: Pranav Mishra <mishrap@dickinson.edu>
Co-authored-by: Pranav Mishra <mishrap@dickinson.edu>
Co-authored-by: Pranav Mishra <mishrap@dickinson.edu>
Co-authored-by: Shahir Ahmed <ahmeds@dickinson.edu>
Co-authored-by: Pranav Mishra <mishrap@dickinson.edu>
…lWidth

Co-authored-by: Shahir Ahmed <ahmeds@dickinson.edu>
…fferent lines

Co-authored-by: Shahir Ahmed <ahmeds@dickinson.edu>
Co-authored-by: Pranav Mishra <mishrap@dickinson.edu>
@Shahir-47
Copy link
Author

Hey @sidharthv96,

In this PR, @pranavm2109 and I introduced a new journey theme variable called maxLabelWidth to allow users to control the maximum width of actor labels in journey diagrams. The configuration is defined as follows:

maxLabelWidth:
  description: Maximum width of actor labels
  type: integer
  default: 360
  minimum: 240
  maximum: 480

Key updates include:

  • Enhanced Text-Wrapping:

    • If a word exceeds the max width, it’s split with a hyphen at the break, and the remainder resumes on the next line.
    • If the break occurs at whitespace, the new word starts on a new line without any hyphen.
  • Improved Layout Consistency:

    • Added tests to ensure no line exceeds the maxLabelWidth so that the spacing between the label and diagram remains consistent.
    • Verified that when a label wraps, the appropriate margin is maintained between the longest legend line and the diagram.
  • Comprehensive Testing:

    • Tests confirm that a single long word wraps correctly with hyphenation.
    • Tests ensure that wrapping on whitespace omits the hyphen.
    • Tests also check that the spacing (margin) between the legend and the diagram is consistent based on the maxLabelWidth setting.

If there’s nothing else, this PR is good to go!

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.

not correctly show title
3 participants