fix: edge label rendering for ER and requirement diagrams when flowchart: { htmlLabels: false }

on-behalf-of: @Mermaid-Chart <hello@mermaidchart.com>
This commit is contained in:
darshanr0107
2026-01-06 19:53:52 +05:30
parent d5bc07dc0c
commit aac86f7de3
6 changed files with 76 additions and 1 deletions
+5
View File
@@ -0,0 +1,5 @@
---
'mermaid': patch
---
fix: Ensure correct edge label rendering for ER and requirement diagrams when flowchart htmlLabels are false
@@ -457,4 +457,18 @@ ORDER ||--|{ LINE-ITEM : contains
);
});
});
it('should render edge labels correctly when flowchart htmlLabels is false', () => {
imgSnapshotTest(
`
erDiagram
CUSTOMER ||--o{ ORDER : places
ORDER ||--|{ LINE-ITEM : contains
CUSTOMER ||--|{ ADDRESS : "invoiced at"
CUSTOMER ||--|{ ADDRESS : "receives goods at"
ORDER ||--o{ INVOICE : "liable for"
`,
{ logLevel: 1, flowchart: { htmlLabels: false } }
);
});
});
@@ -699,5 +699,42 @@ requirementDiagram
options
);
});
it(`${description}should render edge labels correctly when flowchart htmlLabels is false`, () => {
imgSnapshotTest(
`
requirementDiagram
requirement test_req {
id: 1
text: the test text.
risk: high
verifymethod: test
}
functionalRequirement test_req2 {
id: 1.1
text: the second test text.
risk: low
verifymethod: inspection
}
element test_entity {
type: simulation
}
element test_entity2 {
type: word doc
docRef: reqs/test_entity
}
test_entity - satisfies -> test_req2
test_req - traces -> test_req2
test_req - contains -> test_req2
test_entity2 - verifies -> test_req
test_req <- copies - test_entity2
`,
{ ...options, flowchart: { htmlLabels: false } }
);
});
});
});
@@ -68,6 +68,16 @@ const getStyles = (options: FlowChartStyleOptions) =>
stroke: ${options.lineColor} !important;
stroke-width: 1;
}
.edgeLabel {
background-color: ${options.edgeLabelBackground};
}
.edgeLabel .label rect {
fill: ${options.edgeLabelBackground};
}
.edgeLabel .label text {
fill: ${options.textColor};
}
`;
export default getStyles;
@@ -321,7 +321,7 @@ export class RequirementDB implements DiagramDB {
id: `${relation.src}-${relation.dst}-${counter}`,
start: this.requirements.get(relation.src)?.name ?? this.elements.get(relation.src)?.name,
end: this.requirements.get(relation.dst)?.name ?? this.elements.get(relation.dst)?.name,
label: `&lt;&lt;${relation.type}&gt;&gt;`,
label: `«${relation.type}»`,
classes: 'relationshipLine',
style: ['fill:none', isContains ? '' : 'stroke-dasharray: 10,7'],
labelpos: 'c',
@@ -40,6 +40,15 @@ const getStyles = (options) => `
.relationshipLabel {
fill: ${options.relationLabelColor};
}
.edgeLabel {
background-color: ${options.edgeLabelBackground};
}
.edgeLabel .label rect {
fill: ${options.edgeLabelBackground};
}
.edgeLabel .label text {
fill: ${options.relationLabelColor};
}
.divider {
stroke: ${options.nodeBorder};
stroke-width: 1;