diff --git a/cypress/platform/knsv2.html b/cypress/platform/knsv2.html index 847a8bf24..f77f6b0e7 100644 --- a/cypress/platform/knsv2.html +++ b/cypress/platform/knsv2.html @@ -157,14 +157,14 @@ columns 3 end g h i -
+    
 block-beta
 columns 3
   a b c
   e:3
   f g h
     
-
+    
 block-beta
 columns 1
   db(("DB"))
@@ -180,12 +180,13 @@ columns 1
   C --> D
   style B fill:#f9F,stroke:#333,stroke-width:4px
     
-
+    
 block-beta
-
+  columns 5
   A1:3
   A2:1
   A3
+  B1 B2 B3:3
     
 block-beta
diff --git a/packages/mermaid/src/diagrams/block/layout.ts b/packages/mermaid/src/diagrams/block/layout.ts
index fa162a6da..a9d32d2d2 100644
--- a/packages/mermaid/src/diagrams/block/layout.ts
+++ b/packages/mermaid/src/diagrams/block/layout.ts
@@ -277,17 +277,14 @@ function layoutBlocks(block: Block, db: BlockDB) {
   );
 }
 
-let minX = 0;
-let minY = 0;
-let maxX = 0;
-let maxY = 0;
-
-function findBounds(block: Block) {
+function findBounds(
+  block: Block,
+  { minX, minY, maxX, maxY } = { minX: 0, minY: 0, maxX: 0, maxY: 0 }
+) {
   if (block.size && block.id !== 'root') {
     const { x, y, width, height } = block.size;
     if (x - width / 2 < minX) {
       minX = x - width / 2;
-      // log.debug('Here APA minX', block.id, x, width, minX);
     }
     if (y - height / 2 < minY) {
       minY = y - height / 2;
@@ -301,9 +298,10 @@ function findBounds(block: Block) {
   }
   if (block.children) {
     for (const child of block.children) {
-      findBounds(child);
+      ({ minX, minY, maxX, maxY } = findBounds(child, { minX, minY, maxX, maxY }));
     }
   }
+  return { minX, minY, maxX, maxY };
 }
 
 export function layout(db: BlockDB) {
@@ -318,12 +316,8 @@ export function layout(db: BlockDB) {
   // positionBlock(root, root, db);
   log.debug('getBlocks', JSON.stringify(root, null, 2));
 
-  minX = 0;
-  minY = 0;
-  maxX = 0;
-  maxY = 0;
-  findBounds(root);
-  // log.debug('Here maxX', minX, '--', maxX);
+  const { minX, minY, maxX, maxY } = findBounds(root);
+
   const height = maxY - minY;
   const width = maxX - minX;
   return { x: minX, y: minY, width, height };