mirror of
https://github.com/mermaid-js/mermaid.git
synced 2025-09-21 00:09:51 +02:00
#5237 Fix of alignment with htmlLabels
This commit is contained in:
@@ -203,13 +203,14 @@ export const createText = async (
|
|||||||
config: MermaidConfig
|
config: MermaidConfig
|
||||||
) => {
|
) => {
|
||||||
log.info(
|
log.info(
|
||||||
'XXX createText',
|
'XYZ createText',
|
||||||
text,
|
text,
|
||||||
style,
|
style,
|
||||||
isTitle,
|
isTitle,
|
||||||
classes,
|
classes,
|
||||||
useHtmlLabels,
|
useHtmlLabels,
|
||||||
isNode,
|
isNode,
|
||||||
|
'addSvgBackground: ',
|
||||||
addSvgBackground
|
addSvgBackground
|
||||||
);
|
);
|
||||||
if (useHtmlLabels) {
|
if (useHtmlLabels) {
|
||||||
@@ -226,7 +227,12 @@ export const createText = async (
|
|||||||
return vertexNode;
|
return vertexNode;
|
||||||
} else {
|
} else {
|
||||||
const structuredText = markdownToLines(text, config);
|
const structuredText = markdownToLines(text, config);
|
||||||
const svgLabel = createFormattedText(width, el, structuredText, addSvgBackground);
|
const svgLabel = createFormattedText(
|
||||||
|
width,
|
||||||
|
el,
|
||||||
|
structuredText,
|
||||||
|
text ? addSvgBackground : false
|
||||||
|
);
|
||||||
svgLabel.setAttribute(
|
svgLabel.setAttribute(
|
||||||
'style',
|
'style',
|
||||||
style.replace('fill:', 'color:') + (isNode ? ';text-anchor: middle;' : '')
|
style.replace('fill:', 'color:') + (isNode ? ';text-anchor: middle;' : '')
|
||||||
|
@@ -99,19 +99,11 @@ const rect = async (parent, node) => {
|
|||||||
.attr('height', totalHeight);
|
.attr('height', totalHeight);
|
||||||
}
|
}
|
||||||
const { subGraphTitleTopMargin } = getSubGraphTitleMargins(siteConfig);
|
const { subGraphTitleTopMargin } = getSubGraphTitleMargins(siteConfig);
|
||||||
if (useHtmlLabels) {
|
labelEl.attr(
|
||||||
labelEl.attr(
|
'transform',
|
||||||
'transform',
|
// This puts the label on top of the box instead of inside it
|
||||||
// This puts the label on top of the box instead of inside it
|
`translate(${node.x - bbox.width / 2}, ${node.y - node.height / 2 + subGraphTitleTopMargin})`
|
||||||
`translate(${node.x - bbox.width / 2}, ${node.y - node.height / 2 + subGraphTitleTopMargin})`
|
);
|
||||||
);
|
|
||||||
} else {
|
|
||||||
labelEl.attr(
|
|
||||||
'transform',
|
|
||||||
// This puts the label on top of the box instead of inside it
|
|
||||||
`translate(${node.x}, ${node.y - node.height / 2 + subGraphTitleTopMargin})`
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (labelStyles) {
|
if (labelStyles) {
|
||||||
const span = labelEl.select('span');
|
const span = labelEl.select('span');
|
||||||
|
@@ -25,7 +25,7 @@ export const getLabelStyles = (styleArray) => {
|
|||||||
};
|
};
|
||||||
|
|
||||||
export const insertEdgeLabel = async (elem, edge) => {
|
export const insertEdgeLabel = async (elem, edge) => {
|
||||||
const useHtmlLabels = evaluate(getConfig().flowchart.htmlLabels);
|
let useHtmlLabels = evaluate(getConfig().flowchart.htmlLabels);
|
||||||
|
|
||||||
// Create the actual text element
|
// Create the actual text element
|
||||||
// const labelElement =
|
// const labelElement =
|
||||||
@@ -36,6 +36,7 @@ export const insertEdgeLabel = async (elem, edge) => {
|
|||||||
// addSvgBackground: true,
|
// addSvgBackground: true,
|
||||||
// })
|
// })
|
||||||
// : await createLabel(edge.label, getLabelStyles(edge.labelStyle));
|
// : await createLabel(edge.label, getLabelStyles(edge.labelStyle));
|
||||||
|
|
||||||
const labelElement = await createText(elem, edge.label, {
|
const labelElement = await createText(elem, edge.label, {
|
||||||
style: getLabelStyles(edge.labelStyle),
|
style: getLabelStyles(edge.labelStyle),
|
||||||
useHtmlLabels,
|
useHtmlLabels,
|
||||||
|
Reference in New Issue
Block a user