Merge pull request #6739 from kriss-u/bug/6681_td_tb_behavior

fix: trim the direction string in flowchart
This commit is contained in:
shubham-mermaid
2025-07-29 09:43:32 +00:00
committed by GitHub
3 changed files with 24 additions and 1 deletions

View File

@@ -0,0 +1,5 @@
---
'mermaid': patch
---
fix: Update flowchart direction TD's behavior to be the same as TB

View File

@@ -165,3 +165,20 @@ describe('flow db getData', () => {
expect(edges[3].curve).toBe('stepBefore'); expect(edges[3].curve).toBe('stepBefore');
}); });
}); });
describe('flow db direction', () => {
let flowDb: FlowDB;
beforeEach(() => {
flowDb = new FlowDB();
});
it('should set direction to TB when TD is set', () => {
flowDb.setDirection('TD');
expect(flowDb.getDirection()).toBe('TB');
});
it('should correctly set direction irrespective of leading spaces', () => {
flowDb.setDirection(' TD');
expect(flowDb.getDirection()).toBe('TB');
});
});

View File

@@ -406,7 +406,8 @@ You have to call mermaid.initialize.`
* *
*/ */
public setDirection(dir: string) { public setDirection(dir: string) {
this.direction = dir; this.direction = dir.trim();
if (/.*</.exec(this.direction)) { if (/.*</.exec(this.direction)) {
this.direction = 'RL'; this.direction = 'RL';
} }