From e9ce8cf4da9062d85098042044822100889bb0dd Mon Sep 17 00:00:00 2001 From: Krishna Upadhyay <24423580+kriss-u@users.noreply.github.com> Date: Thu, 10 Jul 2025 21:39:19 -0500 Subject: [PATCH 1/2] fix: trim the direction string in flowchart --- .changeset/smart-humans-cover.md | 5 +++++ packages/mermaid/src/diagrams/flowchart/flowDb.ts | 3 ++- 2 files changed, 7 insertions(+), 1 deletion(-) create mode 100644 .changeset/smart-humans-cover.md diff --git a/.changeset/smart-humans-cover.md b/.changeset/smart-humans-cover.md new file mode 100644 index 000000000..4408e0a9c --- /dev/null +++ b/.changeset/smart-humans-cover.md @@ -0,0 +1,5 @@ +--- +'mermaid': patch +--- + +fix: Update flowchart direction TD's behavior to be the same as TB diff --git a/packages/mermaid/src/diagrams/flowchart/flowDb.ts b/packages/mermaid/src/diagrams/flowchart/flowDb.ts index 65f8c4a05..303ad0e66 100644 --- a/packages/mermaid/src/diagrams/flowchart/flowDb.ts +++ b/packages/mermaid/src/diagrams/flowchart/flowDb.ts @@ -403,7 +403,8 @@ You have to call mermaid.initialize.` * */ public setDirection(dir: string) { - this.direction = dir; + this.direction = dir.trim(); + if (/.* Date: Thu, 10 Jul 2025 22:17:30 -0500 Subject: [PATCH 2/2] test: add tests for directions in flowchart --- .../src/diagrams/flowchart/flowDb.spec.ts | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/packages/mermaid/src/diagrams/flowchart/flowDb.spec.ts b/packages/mermaid/src/diagrams/flowchart/flowDb.spec.ts index 8d12de00b..56d3cfb57 100644 --- a/packages/mermaid/src/diagrams/flowchart/flowDb.spec.ts +++ b/packages/mermaid/src/diagrams/flowchart/flowDb.spec.ts @@ -126,3 +126,20 @@ describe('flow db getData', () => { expect(edges[0].curve).toBe('basis'); }); }); + +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'); + }); +});