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.spec.ts b/packages/mermaid/src/diagrams/flowchart/flowDb.spec.ts index 44a6ed052..3e4034e3d 100644 --- a/packages/mermaid/src/diagrams/flowchart/flowDb.spec.ts +++ b/packages/mermaid/src/diagrams/flowchart/flowDb.spec.ts @@ -165,3 +165,20 @@ describe('flow db getData', () => { 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'); + }); +}); diff --git a/packages/mermaid/src/diagrams/flowchart/flowDb.ts b/packages/mermaid/src/diagrams/flowchart/flowDb.ts index b729a85e0..632633730 100644 --- a/packages/mermaid/src/diagrams/flowchart/flowDb.ts +++ b/packages/mermaid/src/diagrams/flowchart/flowDb.ts @@ -406,7 +406,8 @@ You have to call mermaid.initialize.` * */ public setDirection(dir: string) { - this.direction = dir; + this.direction = dir.trim(); + if (/.*