Merge pull request #6588 from mermaid-js/omkar/fix-er-diagram-styling

Fix: Apply proper styling for Mermaid ER diagrams
This commit is contained in:
Ashish Jain
2025-05-13 11:48:18 +00:00
committed by GitHub
2 changed files with 18 additions and 1 deletions

View File

@@ -0,0 +1,5 @@
---
'mermaid': patch
---
Fix stroke styles for ER diagram to correctly apply path and row-specific styles

View File

@@ -40,7 +40,7 @@ export async function erBox<T extends SVGGraphicsElement>(parent: D3Selection<T>
let TEXT_PADDING = config.er?.entityPadding ?? 6;
const { cssStyles } = node;
const { labelStyles } = styles2String(node);
const { labelStyles, nodeStyles } = styles2String(node);
// Draw rect if no attributes are found
if (entityNode.attributes.length === 0 && node.label) {
@@ -295,6 +295,18 @@ export async function erBox<T extends SVGGraphicsElement>(parent: D3Selection<T>
updateNodeBounds(node, rect);
if (nodeStyles && node.look !== 'handDrawn') {
const allStyle = nodeStyles.split(';');
const strokeStyles = allStyle
?.filter((e) => {
return e.includes('stroke');
})
?.map((s) => `${s}`)
.join('; ');
shapeSvg.selectAll('path').attr('style', strokeStyles ?? '');
shapeSvg.selectAll('.row-rect-even path').attr('style', nodeStyles);
}
node.intersect = function (point) {
return intersect.rect(node, point);
};