Skip to content

Commit

Permalink
#3358 Removed logging, fixed som tests
Browse files Browse the repository at this point in the history
  • Loading branch information
knsv committed Jan 18, 2024
1 parent bbc7fe6 commit a0d328d
Show file tree
Hide file tree
Showing 11 changed files with 814 additions and 571 deletions.
29 changes: 21 additions & 8 deletions cypress/platform/knsv2.html
Original file line number Diff line number Diff line change
Expand Up @@ -64,11 +64,24 @@
</head>
<body>
<pre id="diagram" class="mermaid">
block-beta
columns 3
block1["Block 1"]
blockArrow<["&nbsp;&nbsp;&nbsp;"]>(right)
block2["Block 2"]
</pre>
<pre id="diagram" class="mermaid2">
block-beta
columns 5
A space B
A --x B
</pre>
<pre id="diagram" class="mermaid2">
block-beta
columns 3
a["A wide one"] b:2 c:2 d
</pre>
<pre id="diagram" class="mermaid">
<pre id="diagram" class="mermaid2">
block-beta
block:e
f
Expand Down Expand Up @@ -96,7 +109,7 @@
j

</pre>
<pre id="diagram" class="mermaid">
<pre id="diagram" class="mermaid2">
block-beta
columns 3
a b:2
Expand All @@ -105,14 +118,14 @@
end
g h i
</pre>
<pre id="diagram" class="mermaid">
<pre id="diagram" class="mermaid2">
block-beta
columns 3
a b c
e:3
f g h
</pre>
<pre id="diagram" class="mermaid">
<pre id="diagram" class="mermaid2">
block-beta
columns 1
db(("DB"))
Expand All @@ -128,30 +141,30 @@
C --> D
style B fill:#f9F,stroke:#333,stroke-width:4px
</pre>
<pre id="diagram" class="mermaid">
<pre id="diagram" class="mermaid2">
block-beta

A1:3
A2:1
A3
</pre>
<pre id="diagram" class="mermaid">
<pre id="diagram" class="mermaid2">
block-beta
block
D
E
end
db("This is the text in the box")
</pre>
<pre id="diagram" class="mermaid">
<pre id="diagram" class="mermaid2">
block-beta

block
D
end
A["A: I am a wide one"]
</pre>
<pre id="diagram" class="mermaid">
<pre id="diagram" class="mermaid2">
block-beta
A["square"]
B("rounded")
Expand Down
2 changes: 1 addition & 1 deletion packages/mermaid/src/dagre-wrapper/createLabel.js
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ const createLabel = (_vertexText, style, isTitle, isNode) => {
if (evaluate(getConfig().flowchart.htmlLabels)) {
// TODO: addHtmlLabel accepts a labelStyle. Do we possibly have that?
vertexText = vertexText.replace(/\\n|\n/g, '<br />');
log.info('vertexText' + vertexText);
log.debug('vertexText' + vertexText);
const node = {
isNode,
label: decodeEntities(vertexText).replace(
Expand Down
10 changes: 6 additions & 4 deletions packages/mermaid/src/diagrams/block/blockDB.ts
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ const populateBlockDatabase = (_blockList: Block[], parent: Block): void => {
if (!block.label) {
if (block.type === 'composite') {
block.label = '';
console.log('abc89 composite', block);
// log.debug('abc89 composite', block);
} else {
block.label = block.id;
}
Expand All @@ -175,13 +175,15 @@ const populateBlockDatabase = (_blockList: Block[], parent: Block): void => {
populateBlockDatabase(block.children, block);
}
if (block.type === 'space') {
// log.debug('abc95 space', block);
const w = block.width || 1;
for (let j = 0; j < w; j++) {
const newBlock = clone(block);
newBlock.id = newBlock.id + '-' + j;
blockDatabase[newBlock.id] = newBlock;
children.push(newBlock);
}
// log.debug('abc95 space2', children);
} else {
if (newBlock) {
children.push(block);
Expand All @@ -205,7 +207,7 @@ const links: Link[] = [];
let rootBlock = { id: 'root', type: 'composite', children: [], columns: -1 } as Block;

const clear = (): void => {
log.info('Clear called');
log.debug('Clear called');
commonClear();
rootBlock = { id: 'root', type: 'composite', children: [], columns: -1 } as Block;
blockDatabase = { root: rootBlock };
Expand Down Expand Up @@ -290,7 +292,7 @@ const setHierarchy = (block: Block[]): void => {
log.debug('The document from parsing', JSON.stringify(block, null, 2));
rootBlock.children = block;
populateBlockDatabase(block, rootBlock);
log.debug('abc88 The document after popuplation', JSON.stringify(rootBlock, null, 2));
// log.debug('abc95 The document after popuplation', JSON.stringify(rootBlock, null, 2));
blocks = rootBlock.children;
};

Expand Down Expand Up @@ -322,7 +324,7 @@ type IGetBlocks = () => Block[];
*/
const getBlocksFlat: IGetBlocks = () => {
const result: Block[] = [];
console.log('abc88 getBlocksFlat', blockDatabase);
// log.debug('abc88 getBlocksFlat', blockDatabase);
const keys = Object.keys(blockDatabase);
for (const key of keys) {
result.push(blockDatabase[key]);
Expand Down
2 changes: 1 addition & 1 deletion packages/mermaid/src/diagrams/block/blockRenderer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ import { configureSvgSize } from '../../setupGraphViewbox.js';
* @returns {object} ClassDef styles
*/
export const getClasses = function (text: any, diagObj: any) {
log.info('Extracting classes', diagObj.db.getClasses());
log.debug('Extracting classes', diagObj.db.getClasses());
try {
return diagObj.db.getClasses();
} catch (e) {
Expand Down
2 changes: 1 addition & 1 deletion packages/mermaid/src/diagrams/block/layout.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,6 @@ describe('Layout', function () {
expect(calculateBlockPosition(2, 2)).toEqual({ px: 0, py: 1 });
expect(calculateBlockPosition(2, 3)).toEqual({ px: 1, py: 1 });
expect(calculateBlockPosition(2, 4)).toEqual({ px: 0, py: 2 });
expect(calculateBlockPosition(1, 3)).toEqual({ px: 0, py: 2 });
expect(calculateBlockPosition(1, 3)).toEqual({ px: 0, py: 3 });
});
});
80 changes: 43 additions & 37 deletions packages/mermaid/src/diagrams/block/layout.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ interface BlockPosition {
}

export function calculateBlockPosition(columns: number, position: number): BlockPosition {
console.log('calculateBlockPosition abc89', columns, position);
// log.debug('calculateBlockPosition abc89', columns, position);
// Ensure that columns is a positive integer
if (columns === 0 || !Number.isInteger(columns)) {
throw new Error('Columns must be an integer !== 0.');
Expand All @@ -31,18 +31,18 @@ export function calculateBlockPosition(columns: number, position: number): Block
// Calculate posX and posY
const px = position % columns;
const py = Math.floor(position / columns);
console.log('calculateBlockPosition abc89', columns, position, '=> (', px, py, ')');
// log.debug('calculateBlockPosition abc89', columns, position, '=> (', px, py, ')');
return { px, py };
}

const getMaxChildSize = (block: Block) => {
let maxWidth = 0;
let maxHeight = 0;
// find max width of children
console.log('getMaxChildSize abc95 (start) parent:', block.id);
// log.debug('getMaxChildSize abc95 (start) parent:', block.id);
for (const child of block.children) {
const { width, height, x, y } = child.size || { width: 0, height: 0, x: 0, y: 0 };
console.log(
log.debug(
'getMaxChildSize abc95 child:',
child.id,
'width:',
Expand All @@ -52,8 +52,12 @@ const getMaxChildSize = (block: Block) => {
'x:',
x,
'y:',
y
y,
child.type
);
if (child.type === 'space') {
continue;
}
if (width > maxWidth) {
maxWidth = width / (block.w || 1);
}
Expand All @@ -70,15 +74,23 @@ function setBlockSizes(
sieblingWidth: number = 0,
sieblingHeight: number = 0
) {
console.log(
log.debug(
'setBlockSizes abc95 (start)',
block.id,
block?.size?.x,
'block width =',
block?.size?.width,
block?.size,
'sieblingWidth',
sieblingWidth
);
if (!block?.size?.width) {
block.size = {
width: sieblingWidth,
height: sieblingHeight,
x: 0,
y: 0,
};
}
const totalWidth = 0;
const totalHeight = 0;
let maxWidth = 0;
Expand All @@ -92,31 +104,25 @@ function setBlockSizes(
const childSize = getMaxChildSize(block);
maxWidth = childSize.width;
maxHeight = childSize.height;
console.log(
'setBlockSizes abc95 maxWidth of',
block.id,
':s children is ',
maxWidth,
maxHeight
);
log.debug('setBlockSizes abc95 maxWidth of', block.id, ':s children is ', maxWidth, maxHeight);

// set width of block to max width of children
for (const child of block.children) {
if (child.size) {
// console.log(
// 'abc95 Setting size of children of',
// block.id,
// 'id=',
// child.id,
// maxWidth,
// maxHeight,
// child.size
// );
log.debug(
'abc95 Setting size of children of',
block.id,
'id=',
child.id,
maxWidth,
maxHeight,
child.size
);
child.size.width = maxWidth * child.w + padding * (child.w - 1);
child.size.height = maxHeight;
child.size.x = 0;
child.size.y = 0;
console.log(
log.debug(
'abc95 updating size of ',
block.id,
' children child:',
Expand All @@ -129,9 +135,9 @@ function setBlockSizes(
}
}
for (const child of block.children) {
// console.log('abc95 fin 2 Setting size', child.id, maxWidth, maxHeight, child.size);
// log.debug('abc95 fin 2 Setting size', child.id, maxWidth, maxHeight, child.size);
setBlockSizes(child, db, maxWidth, maxHeight);
// console.log('abc95 fin 3 Setting size', child.id, maxWidth, maxHeight, child.size);
// log.debug('abc95 fin 3 Setting size', child.id, maxWidth, maxHeight, child.size);
}

const columns = block.columns || -1;
Expand All @@ -151,7 +157,7 @@ function setBlockSizes(
let height = ySize * (maxHeight + padding) + padding;
// If maxWidth
if (width < sieblingWidth) {
console.log(
log.debug(
'Detected to small siebling: abc95',
block.id,
'sieblingWidth',
Expand Down Expand Up @@ -180,7 +186,7 @@ function setBlockSizes(
}
}

console.log(
log.debug(
'abc95 (finale calc)',
block.id,
'xSize',
Expand All @@ -200,7 +206,7 @@ function setBlockSizes(
const num = block.children.length;
if (num > 0) {
const childWidth = (width - num * padding - padding) / num;
// console.log('abc95 (finale calc) width', block.id, width, block.size?.width, childWidth);
// log.debug('abc95 (finale calc) width', block.id, width, block.size?.width, childWidth);
for (const child of block.children) {
if (child.size) {
child.size.width = childWidth;
Expand All @@ -216,7 +222,7 @@ function setBlockSizes(
};
}

console.log(
log.debug(
'setBlockSizes abc94 (done)',
block.id,
block?.size?.x,
Expand All @@ -228,7 +234,7 @@ function setBlockSizes(

function layoutBlocks(block: Block, db: BlockDB) {
log.debug(
'abc89 layout blocks (=>layoutBlocks)',
'abc85 layout blocks (=>layoutBlocks)',
block.id,
'x:',
block?.size?.x,
Expand All @@ -238,7 +244,7 @@ function layoutBlocks(block: Block, db: BlockDB) {
block?.size?.width
);
const columns = block.columns || -1;
console.log('layoutBlocks columns abc91', block.id, '=>', columns, block);
log.debug('layoutBlocks columns abc95', block.id, '=>', columns, block);
if (
block.children && // find max width of children
block.children.length > 0
Expand All @@ -250,7 +256,7 @@ function layoutBlocks(block: Block, db: BlockDB) {

// let first = true;
let columnPos = 0;
console.log('abc91 block?.size?.x', block.id, block?.size?.x);
log.debug('abc91 block?.size?.x', block.id, block?.size?.x);
let startingPosX = block?.size?.x ? block?.size?.x + (-block?.size?.width / 2 || 0) : -padding;
let rowPos = 0;
for (const child of block.children) {
Expand All @@ -265,7 +271,7 @@ function layoutBlocks(block: Block, db: BlockDB) {
rowPos = py;
startingPosX = block?.size?.x || -padding;
}
console.log(
log.debug(
'abc89 layout blocks (child) id:',
child.id,
'Pos:',
Expand Down Expand Up @@ -294,7 +300,7 @@ function layoutBlocks(block: Block, db: BlockDB) {
const halfWidth = width / 2;
child.size.x = startingPosX + padding + halfWidth;

console.log(
log.debug(
'abc91 layout blocks (calc) px, py',
'id:',
child.id,
Expand Down Expand Up @@ -323,7 +329,7 @@ function layoutBlocks(block: Block, db: BlockDB) {
child.size.y =
parent.size.y - parent.size.height / 2 + py * (height + padding) + height / 2 + padding;

console.log(
log.debug(
'abc88 layout blocks (calc) px, py',
'id:',
child.id,
Expand All @@ -347,7 +353,7 @@ function layoutBlocks(block: Block, db: BlockDB) {
layoutBlocks(child, db);
}
columnPos += child?.w || 1;
console.log('abc88 columnsPos', child, columnPos);
log.debug('abc88 columnsPos', child, columnPos);
}
}
log.debug(
Expand Down
Loading

0 comments on commit a0d328d

Please sign in to comment.