Skip to content

Commit

Permalink
mermaid-js#5858 - fix: Timeline node width made dynamic
Browse files Browse the repository at this point in the history
- Refactored timelineRenderer.drawEvents
    - Added DEFAULT_NODE_WIDTH of 150
    - Used conf?.timeline?.width as a dynamic value, or default value if
not provided
- Added integration tests in
cypress/integration/rendering/timeline.spec.ts to cover changes
  • Loading branch information
afmireski committed Nov 30, 2024
1 parent cc29437 commit 146b86c
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 1 deletion.
38 changes: 38 additions & 0 deletions cypress/integration/rendering/timeline.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -161,4 +161,42 @@ describe('Timeline diagram', () => {
{}
);
});

it('11: should render a simple timeline with a custom width of 300', () => {
imgSnapshotTest(
`%%{init: { 'logLevel': 'debug', 'timeline': { 'width': 300 } } }%%
timeline
title History of Social Media Platform
2002 : LinkedIn
2004 : Facebook : Google
2005 : Youtube
2006 : Twitter
2007 : Tumblr
2008 : Instagram
2010 : Pinterest
`,
{
timeline: {
width: 300,
},
}
);
});

it('12: should render a simple timeline with default width of 150', () => {
imgSnapshotTest(
`%%{init: { 'logLevel': 'debug', 'timeline': { 'width': 150 } } }%%
timeline
title History of Social Media Platform
2002 : LinkedIn
2004 : Facebook : Google
2005 : Youtube
2006 : Twitter
2007 : Tumblr
2008 : Instagram
2010 : Pinterest
`,
{}
);
});
});
7 changes: 6 additions & 1 deletion packages/mermaid/src/diagrams/timeline/timelineRenderer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -322,14 +322,19 @@ export const drawEvents = function (
let maxEventHeight = 0;
const eventBeginY = masterY;
masterY = masterY + 100;

const DEFAULT_NODE_WIDTH = 150;

const nodeWidth = conf?.timeline?.width ?? DEFAULT_NODE_WIDTH;

// Draw the events
for (const event of events) {
// create node from event
const eventNode: Block<string, number> = {
descr: event,
section: sectionColor,
number: sectionColor,
width: 150,
width: nodeWidth,
padding: 20,
maxHeight: 50,
};
Expand Down

0 comments on commit 146b86c

Please sign in to comment.