#5237 Fix of alignment with htmlLabels

This commit is contained in:
Knut Sveidqvist
2024-06-25 15:48:19 +02:00
parent fc31b22eb0
commit 9979ea1d74
3 changed files with 15 additions and 16 deletions

View File

@@ -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;' : '')

View File

@@ -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');

View File

@@ -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,