Skip to content

Commit

Permalink
#3358 Fix after review
Browse files Browse the repository at this point in the history
  • Loading branch information
knsv committed Feb 1, 2024
1 parent cd7003e commit 16149ab
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 18 deletions.
9 changes: 5 additions & 4 deletions cypress/platform/knsv2.html
Original file line number Diff line number Diff line change
Expand Up @@ -157,14 +157,14 @@
end
g h i
</pre>
<pre id="diagram" class="mermaid2">
<pre id="diagram" class="mermaid">
block-beta
columns 3
a b c
e:3
f g h
</pre>
<pre id="diagram" class="mermaid2">
<pre id="diagram" class="mermaid">
block-beta
columns 1
db(("DB"))
Expand All @@ -180,12 +180,13 @@
C --> D
style B fill:#f9F,stroke:#333,stroke-width:4px
</pre>
<pre id="diagram" class="mermaid2">
<pre id="diagram" class="mermaid">
block-beta

columns 5
A1:3
A2:1
A3
B1 B2 B3:3
</pre>
<pre id="diagram" class="mermaid2">
block-beta
Expand Down
22 changes: 8 additions & 14 deletions packages/mermaid/src/diagrams/block/layout.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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) {
Expand All @@ -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 };
Expand Down

0 comments on commit 16149ab

Please sign in to comment.