fix: failing ER diagram tests

on-behalf-of: @Mermaid-Chart <hello@mermaidchart.com>
This commit is contained in:
darshanr0107
2025-11-04 18:58:03 +05:30
parent 70c9e6e57a
commit f4debcc7ab
2 changed files with 7 additions and 4 deletions

View File

@@ -81,7 +81,7 @@ const createLabel = async (_vertexText, style, isTitle, isNode) => {
return vertexNode;
} else {
const svgLabel = document.createElementNS('http://www.w3.org/2000/svg', 'text');
svgLabel.setAttribute('style', style.replace('color:', 'fill:'));
svgLabel.setAttribute('style', style ? style.replace('color:', 'fill:') : '');
let rows = [];
if (typeof vertexText === 'string') {
rows = vertexText.split(/\\n|\n|<br\s*\/?>/gi);

View File

@@ -62,10 +62,13 @@ export async function erBox<T extends SVGGraphicsElement>(parent: D3Selection<T>
// drawRect doesn't center non-htmlLabels correctly as of now, so translate label
if (!evaluate(config.htmlLabels)) {
const textElement = shapeSvg.select('text');
const bbox = (textElement.node() as SVGTextElement)?.getBBox();
const textElement = shapeSvg.select('.label text');
const textNode = textElement.node() as SVGTextElement;
if (textNode) {
const bbox = textNode.getBBox();
textElement.attr('transform', `translate(${-bbox.width / 2}, 0)`);
}
}
return shapeSvg;
}