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 timeline title wrapping issue (#6393) #6394

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

Conversation

nourhenta
Copy link

@nourhenta nourhenta commented Mar 20, 2025

📑 Summary

This pull request resolves the issue where timeline titles do not wrap correctly when the text is too long. The problem caused layout issues, such as overflowing or shrinking diagrams, making them unreadable. The fix ensures that timeline titles break into multiple lines and maintain consistent diagram layouts.

Resolves ##6393

📏 Design Decisions

  1. Identified the Problem
  • Found that the title was rendered using an SVG element, which does not support automatic text wrapping.

2.Introduced for Wrapping

Replaced the element with to enable proper wrapping using HTML/CSS.
Updated Code:

if (title) {
  const foreignObject = svg
    .append('foreignObject')
    .attr('x', LEFT_MARGIN) // Adjust position as needed
    .attr('y', TOP_MARGIN) // Adjust vertical position as needed
    .attr('width', diagramWidth - LEFT_MARGIN * 2) // Set width
    .attr('height', WRAPPING_HEIGHT); // Define height for wrapping

  foreignObject
    .append('xhtml:div') // Use xhtml namespace for HTML inside SVG
    .style('font-size', `${conf.fontSize || '16px'}`)
    .style('word-wrap', 'break-word')
    .style('white-space', 'normal')
    .style('text-align', 'center')
    .text(title);
}
  1. Applied CSS Styling for Wrapping
  • word-wrap: break-word; Ensures long words break into multiple lines.
  • white-space: normal; Allows natural line breaks.
  • text-align: center; Centers the title for better readability.
  1. Tested with Long Titles

📋 Tasks

Make sure you

  • 📖 have read the contribution guidelines
  • 💻 have added necessary unit/e2e tests.
  • 📓 have added documentation. Make sure MERMAID_RELEASE_VERSION is used for all new features.
  • 🦋 If your PR makes a change that should be noted in one or more packages' changelogs, generate a changeset by running pnpm changeset and following the prompts. Changesets that add features should be minor and those that fix bugs should be patch. Please prefix changeset messages with feat:, fix:, or chore:.

Copy link

changeset-bot bot commented Mar 20, 2025

⚠️ No Changeset found

Latest commit: cb5028b

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

Copy link

netlify bot commented Mar 20, 2025

Deploy Preview for mermaid-js failed.

Name Link
🔨 Latest commit cb5028b
🔍 Latest deploy log https://app.netlify.com/sites/mermaid-js/deploys/67db89d13d4b61000880c9fc

Copy link

pkg-pr-new bot commented Mar 20, 2025

Open in Stackblitz

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

commit: 130762b

Copy link

codecov bot commented Mar 20, 2025

Codecov Report

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

Project coverage is 3.85%. Comparing base (d602240) to head (130762b).

Files with missing lines Patch % Lines
packages/mermaid/src/diagrams/timeline/svgDraw.js 0.00% 43 Missing ⚠️
.../mermaid/src/diagrams/timeline/timelineRenderer.ts 0.00% 14 Missing ⚠️
Additional details and impacted files

Impacted file tree graph

@@            Coverage Diff             @@
##           develop   #6394      +/-   ##
==========================================
- Coverage     3.86%   3.85%   -0.01%     
==========================================
  Files          402     401       -1     
  Lines        42682   42706      +24     
  Branches       644     644              
==========================================
  Hits          1648    1648              
- Misses       41034   41058      +24     
Flag Coverage Δ
unit 3.85% <0.00%> (-0.01%) ⬇️

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

Files with missing lines Coverage Δ
.../mermaid/src/diagrams/timeline/timelineRenderer.ts 0.39% <0.00%> (-0.02%) ⬇️
packages/mermaid/src/diagrams/timeline/svgDraw.js 0.00% <0.00%> (ø)

... and 1 file with indirect coverage changes

🚀 New features to boost your workflow:
  • Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

Copy link

argos-ci bot commented Mar 20, 2025

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

Awaiting the start of a new Argos build…

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant