mirror of
https://github.com/mermaid-js/mermaid.git
synced 2025-01-28 07:03:17 +08:00
#3358 Fix after review
This commit is contained in:
parent
cd7003e9c1
commit
16149abcc0
@ -157,14 +157,14 @@ columns 3
|
|||||||
end
|
end
|
||||||
g h i
|
g h i
|
||||||
</pre>
|
</pre>
|
||||||
<pre id="diagram" class="mermaid2">
|
<pre id="diagram" class="mermaid">
|
||||||
block-beta
|
block-beta
|
||||||
columns 3
|
columns 3
|
||||||
a b c
|
a b c
|
||||||
e:3
|
e:3
|
||||||
f g h
|
f g h
|
||||||
</pre>
|
</pre>
|
||||||
<pre id="diagram" class="mermaid2">
|
<pre id="diagram" class="mermaid">
|
||||||
block-beta
|
block-beta
|
||||||
columns 1
|
columns 1
|
||||||
db(("DB"))
|
db(("DB"))
|
||||||
@ -180,12 +180,13 @@ columns 1
|
|||||||
C --> D
|
C --> D
|
||||||
style B fill:#f9F,stroke:#333,stroke-width:4px
|
style B fill:#f9F,stroke:#333,stroke-width:4px
|
||||||
</pre>
|
</pre>
|
||||||
<pre id="diagram" class="mermaid2">
|
<pre id="diagram" class="mermaid">
|
||||||
block-beta
|
block-beta
|
||||||
|
columns 5
|
||||||
A1:3
|
A1:3
|
||||||
A2:1
|
A2:1
|
||||||
A3
|
A3
|
||||||
|
B1 B2 B3:3
|
||||||
</pre>
|
</pre>
|
||||||
<pre id="diagram" class="mermaid2">
|
<pre id="diagram" class="mermaid2">
|
||||||
block-beta
|
block-beta
|
||||||
|
@ -277,17 +277,14 @@ function layoutBlocks(block: Block, db: BlockDB) {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
let minX = 0;
|
function findBounds(
|
||||||
let minY = 0;
|
block: Block,
|
||||||
let maxX = 0;
|
{ minX, minY, maxX, maxY } = { minX: 0, minY: 0, maxX: 0, maxY: 0 }
|
||||||
let maxY = 0;
|
) {
|
||||||
|
|
||||||
function findBounds(block: Block) {
|
|
||||||
if (block.size && block.id !== 'root') {
|
if (block.size && block.id !== 'root') {
|
||||||
const { x, y, width, height } = block.size;
|
const { x, y, width, height } = block.size;
|
||||||
if (x - width / 2 < minX) {
|
if (x - width / 2 < minX) {
|
||||||
minX = x - width / 2;
|
minX = x - width / 2;
|
||||||
// log.debug('Here APA minX', block.id, x, width, minX);
|
|
||||||
}
|
}
|
||||||
if (y - height / 2 < minY) {
|
if (y - height / 2 < minY) {
|
||||||
minY = y - height / 2;
|
minY = y - height / 2;
|
||||||
@ -301,9 +298,10 @@ function findBounds(block: Block) {
|
|||||||
}
|
}
|
||||||
if (block.children) {
|
if (block.children) {
|
||||||
for (const child of 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) {
|
export function layout(db: BlockDB) {
|
||||||
@ -318,12 +316,8 @@ export function layout(db: BlockDB) {
|
|||||||
// positionBlock(root, root, db);
|
// positionBlock(root, root, db);
|
||||||
log.debug('getBlocks', JSON.stringify(root, null, 2));
|
log.debug('getBlocks', JSON.stringify(root, null, 2));
|
||||||
|
|
||||||
minX = 0;
|
const { minX, minY, maxX, maxY } = findBounds(root);
|
||||||
minY = 0;
|
|
||||||
maxX = 0;
|
|
||||||
maxY = 0;
|
|
||||||
findBounds(root);
|
|
||||||
// log.debug('Here maxX', minX, '--', maxX);
|
|
||||||
const height = maxY - minY;
|
const height = maxY - minY;
|
||||||
const width = maxX - minX;
|
const width = maxX - minX;
|
||||||
return { x: minX, y: minY, width, height };
|
return { x: minX, y: minY, width, height };
|
||||||
|
Loading…
x
Reference in New Issue
Block a user