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; return vertexNode;
} else { } else {
const svgLabel = document.createElementNS('http://www.w3.org/2000/svg', 'text'); 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 = []; let rows = [];
if (typeof vertexText === 'string') { if (typeof vertexText === 'string') {
rows = vertexText.split(/\\n|\n|<br\s*\/?>/gi); rows = vertexText.split(/\\n|\n|<br\s*\/?>/gi);

View File

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