Skip to content

Commit

Permalink
Fixing issues in mindmaps and class diagram notes after tests
Browse files Browse the repository at this point in the history
  • Loading branch information
knsv committed Apr 4, 2023
1 parent e8799ad commit 1841346
Show file tree
Hide file tree
Showing 5 changed files with 30 additions and 15 deletions.
24 changes: 17 additions & 7 deletions cypress/platform/knsv2.html
Original file line number Diff line number Diff line change
Expand Up @@ -57,12 +57,12 @@
</style>
</head>
<body>
<pre id="diagram" class="mermaid">
<pre id="diagram" class="mermaid2">
flowchart LR
A[A text that needs to be wrapped wraps to another line]
B[A text that needs to be<br/>wrapped wraps to another line]
C["`A text that needs to be wrapped to another line`"]</pre>
<pre id="diagram" class="mermaid">
<pre id="diagram" class="mermaid2">
flowchart LR
C["`A text
that needs
Expand All @@ -71,11 +71,21 @@
way`"]
</pre
>
<pre id="diagram" class="mermaid2">
flowchart-elk LR
b("The dog in the hog... a very<br/>long text about it<br/>Word!")
</pre>
<pre id="diagram" class="mermaid">
mindmap
root
Child3(A node with an icon and with a long text that wraps to keep the node size in check)
</pre
>
<pre id="diagram" class="mermaid">
%%{init: {"theme": "forest"} }%%
mindmap
id1[**Start2**<br/>end]
id2[**Start2**<br />end]
%% Another comment
id3[**Start2**<br>end] %% Comment
id4[**Start2**<br >end<br >the very end]
</pre>
<pre id="diagram" class="mermaid2">
mindmap
id1[`**Start2**
Expand All @@ -89,7 +99,7 @@
and another
`]
</pre>
<pre id="diagram" class="mermaid">
<pre id="diagram" class="mermaid2">
mindmap
id1("`**Root**`"]
id2["`A formatted text... with **bold** and *italics*`"]
Expand Down
14 changes: 9 additions & 5 deletions packages/mermaid/src/dagre-wrapper/nodes.js
Original file line number Diff line number Diff line change
Expand Up @@ -316,15 +316,19 @@ const rect = (parent, node) => {
// add the rect
const rect = shapeSvg.insert('rect', ':first-child');

const totalWidth = bbox.width + node.padding * 2;
const totalHeight = bbox.height + node.padding * 2;
// const totalWidth = bbox.width + node.padding * 2;
// const totalHeight = bbox.height + node.padding * 2;
const totalWidth = bbox.width + node.padding;
const totalHeight = bbox.height + node.padding;
rect
.attr('class', 'basic label-container')
.attr('style', node.style)
.attr('rx', node.rx)
.attr('ry', node.ry)
.attr('x', -bbox.width / 2 - node.padding)
.attr('y', -bbox.height / 2 - node.padding)
// .attr('x', -bbox.width / 2 - node.padding)
// .attr('y', -bbox.height / 2 - node.padding)
.attr('x', -bbox.width / 2 - halfPadding)
.attr('y', -bbox.height / 2 - halfPadding)
.attr('width', totalWidth)
.attr('height', totalHeight);

Expand All @@ -351,7 +355,7 @@ const rect = (parent, node) => {
const labelRect = (parent, node) => {
const { shapeSvg } = labelHelper(parent, node, 'label', true);

log.info('Classes = ', node.classes);
log.trace('Classes = ', node.classes);
// add the rect
const rect = shapeSvg.insert('rect', ':first-child');

Expand Down
2 changes: 1 addition & 1 deletion packages/mermaid/src/diagrams/mindmap/mindmapRenderer.js
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,7 @@ export const draw = async (text, id, version, diagObj) => {
// Parse the graph definition
diagObj.parser.parse(text);

log.debug('Renering mindmap diagram\n' + text, diagObj);
log.debug('Rendering mindmap diagram\n' + text, diagObj.parser);

const securityLevel = getConfig().securityLevel;
// Handle root and Document for when rendering in sandbox mode
Expand Down
2 changes: 1 addition & 1 deletion packages/mermaid/src/diagrams/mindmap/parser/mindmap.jison
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@

%%

\s*\%\%.* {yy.getLogger().trace('Found comment',yytext);}
\s*\%\%.* {yy.getLogger().trace('Found comment',yytext); return 'SPACELINE';}
// \%\%[^\n]*\n /* skip comments */
"mindmap" return 'MINDMAP';
":::" { this.begin('CLASS'); }
Expand Down
3 changes: 2 additions & 1 deletion packages/mermaid/src/diagrams/mindmap/svgDraw.js
Original file line number Diff line number Diff line change
Expand Up @@ -217,7 +217,8 @@ export const drawNode = function (elem, node, fullSection, conf) {

// Create the wrapped text element
const textElem = nodeElem.append('g');
const newEl = createText(textElem, node.descr, {
const description = node.descr.replace(/(<br\/*>)/g, '\n');
const newEl = createText(textElem, description, {
useHtmlLabels: htmlLabels,
width: node.width,
classes: 'mindmap-node-label',
Expand Down

0 comments on commit 1841346

Please sign in to comment.