Skip to content

Timeline Title Does Not Wrap Correctly #6393

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

Open
nourhenta opened this issue Mar 19, 2025 · 3 comments · May be fixed by #6405
Open

Timeline Title Does Not Wrap Correctly #6393

nourhenta opened this issue Mar 19, 2025 · 3 comments · May be fixed by #6405
Labels
Status: Triage Needs to be verified, categorized, etc Type: Bug / Error Something isn't working or is incorrect

Comments

@nourhenta
Copy link

nourhenta commented Mar 19, 2025

Description

The timeline title in Mermaid does not wrap properly when it is too long. Instead of breaking into multiple lines, it remains on a single line, causing layout issues such as:

  • The timeline diagram shrinking progressively as the title length increases.
  • Horizontal overflow, making the diagram unreadable.

Steps to reproduce

  1. Open Mermaid's live editor (Mermaid Live Editor).
  2. Paste the example code provided into the editor.
  3. Observe how the timeline title behaves:
  • The diagram shrinks progressively as the title length increases, making it unreadable.

Screenshots

Image

Code Sample

timeline  
title This is an extremely long timeline title that should be properly wrapped across multiple lines without affecting the layout of the diagram or shrinking its size unnecessarily
section Phase 1  
Task 1 :2023-01-01 :2023-02-01  
Task 2 :2023-02-01 :2023-03-01  
section Phase 2  
Task 3 :2023-03-01 :2023-04-01  
Task 4 :2023-04-01 :2023-05-01

Setup

Environment Details
• Mermaid Version:11.4.1
• Browser Tested:
Microsoft Edge (Version: 132.0.2957.115)
• Operating System: (Windows 11)

@nourhenta nourhenta added Status: Triage Needs to be verified, categorized, etc Type: Bug / Error Something isn't working or is incorrect labels Mar 19, 2025
nourhenta added a commit to nourhenta/mermaid that referenced this issue Mar 20, 2025
@nourhenta
Copy link
Author

To resolve this issue, I replaced the element with an SVG element, allowing HTML/CSS to properly render and style the title.

Steps Taken

  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

Used a long title example to ensure proper wrapping and confirm that the timeline diagram remains unaffected.
Screenshots

Image

Image

Mermaid Version: 11.4.1

@BambioGaming
Copy link

Great work on addressing the title wrapping issue! The fix makes a big improvement in readability.

I have a small suggestion to further enhance the title styling for better emphasis. Currently, the title blends in with other text, making it less prominent in the diagram. To improve readability and presentation, the title could:

  • Be larger (e.g., 24px or more).
  • Be bold (font-weight: bold).
  • Be center-aligned properly.

This small tweak would make titles stand out better.

@nour0205 nour0205 linked a pull request Mar 22, 2025 that will close this issue
@nour0205
Copy link

Hi @nourhenta 👋

Thanks for raising this issue! I’ve submitted a fix #6405 that ensures long timeline titles are properly wrapped using an SVG containing a styled XHTML


This prevents layout issues like shrinking diagrams or overflow while keeping the title centered and readable.

Here’s how the wrapped title looks now:

Image

Let me know if you have any feedback!

nourhenta added a commit to nourhenta/mermaid that referenced this issue Apr 6, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Status: Triage Needs to be verified, categorized, etc Type: Bug / Error Something isn't working or is incorrect
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants