mirror of
https://github.com/mermaid-js/mermaid.git
synced 2025-01-28 07:03:17 +08:00
Adding back create label for the cases where you do not want markdown text
This commit is contained in:
parent
65f9b29b86
commit
f27ca07371
@ -917,4 +917,24 @@ graph TD
|
|||||||
}
|
}
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
|
it('68: should be able to string and markdown labels (#5824)', () => {
|
||||||
|
imgSnapshotTest(
|
||||||
|
`
|
||||||
|
flowchart TB
|
||||||
|
mermaid{"What is\nyourmermaid version?"} --> v10["<11"] --"\`<**1**1\`"--> fine["No bug"]
|
||||||
|
mermaid --> v11[">= v11"] -- ">= v11" --> broken["Affected by https://github.com/mermaid-js/mermaid/issues/5824"]
|
||||||
|
subgraph subgraph1["\`How to fix **fix**\`"]
|
||||||
|
broken --> B["B"]
|
||||||
|
end
|
||||||
|
githost["Github, Gitlab, BitBucket, etc."]
|
||||||
|
githost2["\`Github, Gitlab, BitBucket, etc.\`"]
|
||||||
|
a["1."]
|
||||||
|
b["- x"]
|
||||||
|
`,
|
||||||
|
{
|
||||||
|
flowchart: { htmlLabels: true },
|
||||||
|
securityLevel: 'loose',
|
||||||
|
}
|
||||||
|
);
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
@ -116,7 +116,7 @@ flowchart LR
|
|||||||
|
|
||||||
|
|
||||||
</pre>
|
</pre>
|
||||||
<pre id="diagram4" class="mermaid">
|
<pre id="diagram4" class="mermaid2">
|
||||||
---
|
---
|
||||||
config:
|
config:
|
||||||
layout: elk
|
layout: elk
|
||||||
@ -155,21 +155,21 @@ flowchart LR
|
|||||||
n8@{ shape: rect}
|
n8@{ shape: rect}
|
||||||
|
|
||||||
</pre>
|
</pre>
|
||||||
<pre id="diagram4" class="mermaid2">
|
<pre id="diagram4" class="mermaid">
|
||||||
---
|
---
|
||||||
config:
|
title: https://github.com/mermaid-js/mermaid/issues/5824
|
||||||
layout: elk
|
|
||||||
---
|
---
|
||||||
flowchart LR
|
%% 6048, 5824
|
||||||
subgraph s1["Untitled subgraph"]
|
flowchart TB
|
||||||
n1["Evaluate"]
|
mermaid{"What is\nyourmermaid version?"} --> v10["<11"] --"`<**1**1`"--> fine["No bug"]
|
||||||
n2["Option 1"]
|
mermaid --> v11[">= v11"] -- ">= v11" --> broken["Affected by https://github.com/mermaid-js/mermaid/issues/5824"]
|
||||||
end
|
subgraph subgraph1["`How to fix **fix**`"]
|
||||||
n1 -- One --> n2
|
broken --> B["B"]
|
||||||
|
end
|
||||||
|
githost["Github, Gitlab, BitBucket, etc."]
|
||||||
|
githost2["`Github, Gitlab, BitBucket, etc.`"]
|
||||||
|
a["1."]
|
||||||
|
b["- x"]
|
||||||
</pre>
|
</pre>
|
||||||
<pre id="diagram4" class="mermaid2">
|
<pre id="diagram4" class="mermaid2">
|
||||||
---
|
---
|
||||||
|
@ -896,6 +896,7 @@ const addNodeFromVertex = (
|
|||||||
const baseNode = {
|
const baseNode = {
|
||||||
id: vertex.id,
|
id: vertex.id,
|
||||||
label: vertex.text,
|
label: vertex.text,
|
||||||
|
labelType: vertex.labelType,
|
||||||
labelStyle: '',
|
labelStyle: '',
|
||||||
parentId,
|
parentId,
|
||||||
padding: config.flowchart?.padding || 8,
|
padding: config.flowchart?.padding || 8,
|
||||||
@ -1002,6 +1003,7 @@ export const getData = () => {
|
|||||||
end: rawEdge.end,
|
end: rawEdge.end,
|
||||||
type: rawEdge.type ?? 'normal',
|
type: rawEdge.type ?? 'normal',
|
||||||
label: rawEdge.text,
|
label: rawEdge.text,
|
||||||
|
labelType: rawEdge.labelType,
|
||||||
labelpos: 'c',
|
labelpos: 'c',
|
||||||
thickness: rawEdge.stroke,
|
thickness: rawEdge.stroke,
|
||||||
minlen: rawEdge.length,
|
minlen: rawEdge.length,
|
||||||
|
@ -26,12 +26,16 @@ export const getLabelStyles = (styleArray) => {
|
|||||||
export const insertEdgeLabel = async (elem, edge) => {
|
export const insertEdgeLabel = async (elem, edge) => {
|
||||||
let useHtmlLabels = evaluate(getConfig().flowchart.htmlLabels);
|
let useHtmlLabels = evaluate(getConfig().flowchart.htmlLabels);
|
||||||
|
|
||||||
const labelElement = await createText(elem, edge.label, {
|
const labelElement =
|
||||||
style: getLabelStyles(edge.labelStyle),
|
edge.labelType === 'markdown'
|
||||||
useHtmlLabels,
|
? await createText(elem, edge.label, {
|
||||||
addSvgBackground: true,
|
style: getLabelStyles(edge.labelStyle),
|
||||||
isNode: false,
|
useHtmlLabels,
|
||||||
});
|
addSvgBackground: true,
|
||||||
|
isNode: false,
|
||||||
|
})
|
||||||
|
: await createLabel(edge.label, getLabelStyles(edge.labelStyle), undefined, false);
|
||||||
|
|
||||||
log.info('abc82', edge, edge.labelType);
|
log.info('abc82', edge, edge.labelType);
|
||||||
|
|
||||||
// Create outer g, edgeLabel, this will be positioned after graph layout
|
// Create outer g, edgeLabel, this will be positioned after graph layout
|
||||||
|
@ -1,3 +1,4 @@
|
|||||||
|
import createLabel from '../createLabel.js';
|
||||||
import { createText } from '../../createText.js';
|
import { createText } from '../../createText.js';
|
||||||
import type { Node } from '../../types.js';
|
import type { Node } from '../../types.js';
|
||||||
import { getConfig } from '../../../diagram-api/diagramAPI.js';
|
import { getConfig } from '../../../diagram-api/diagramAPI.js';
|
||||||
@ -40,14 +41,26 @@ export const labelHelper = async <T extends SVGGraphicsElement>(
|
|||||||
label = typeof node.label === 'string' ? node.label : node.label[0];
|
label = typeof node.label === 'string' ? node.label : node.label[0];
|
||||||
}
|
}
|
||||||
|
|
||||||
const text = await createText(labelEl, sanitizeText(decodeEntities(label), getConfig()), {
|
let text;
|
||||||
useHtmlLabels,
|
if (node.labelType !== 'string') {
|
||||||
width: node.width || getConfig().flowchart?.wrappingWidth,
|
text = await createText(labelEl, sanitizeText(decodeEntities(label), getConfig()), {
|
||||||
// @ts-expect-error -- This is currently not used. Should this be `classes` instead?
|
useHtmlLabels,
|
||||||
cssClasses: 'markdown-node-label',
|
width: node.width || getConfig().flowchart?.wrappingWidth,
|
||||||
style: node.labelStyle,
|
// @ts-expect-error -- This is currently not used. Should this be `classes` instead?
|
||||||
addSvgBackground: !!node.icon || !!node.img,
|
cssClasses: 'markdown-node-label',
|
||||||
});
|
style: node.labelStyle,
|
||||||
|
addSvgBackground: !!node.icon || !!node.img,
|
||||||
|
});
|
||||||
|
} else {
|
||||||
|
const labelElement = await createLabel(
|
||||||
|
sanitizeText(decodeEntities(label), getConfig()),
|
||||||
|
node.labelStyle,
|
||||||
|
false,
|
||||||
|
true
|
||||||
|
);
|
||||||
|
text = labelEl.node()?.appendChild(labelElement);
|
||||||
|
}
|
||||||
|
|
||||||
// Get the size of the label
|
// Get the size of the label
|
||||||
let bbox = text.getBBox();
|
let bbox = text.getBBox();
|
||||||
const halfPadding = (node?.padding ?? 0) / 2;
|
const halfPadding = (node?.padding ?? 0) / 2;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user