Skip to content

Commit aac86f7

Browse files
committed
fix: edge label rendering for ER and requirement diagrams when flowchart: { htmlLabels: false }
on-behalf-of: @Mermaid-Chart <hello@mermaidchart.com>
1 parent d5bc07d commit aac86f7

File tree

6 files changed

+76
-1
lines changed

6 files changed

+76
-1
lines changed

.changeset/salty-seals-guess.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'mermaid': patch
3+
---
4+
5+
fix: Ensure correct edge label rendering for ER and requirement diagrams when flowchart htmlLabels are false

cypress/integration/rendering/erDiagram.spec.js

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -457,4 +457,18 @@ ORDER ||--|{ LINE-ITEM : contains
457457
);
458458
});
459459
});
460+
461+
it('should render edge labels correctly when flowchart htmlLabels is false', () => {
462+
imgSnapshotTest(
463+
`
464+
erDiagram
465+
CUSTOMER ||--o{ ORDER : places
466+
ORDER ||--|{ LINE-ITEM : contains
467+
CUSTOMER ||--|{ ADDRESS : "invoiced at"
468+
CUSTOMER ||--|{ ADDRESS : "receives goods at"
469+
ORDER ||--o{ INVOICE : "liable for"
470+
`,
471+
{ logLevel: 1, flowchart: { htmlLabels: false } }
472+
);
473+
});
460474
});

cypress/integration/rendering/requirementDiagram-unified.spec.js

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -699,5 +699,42 @@ requirementDiagram
699699
options
700700
);
701701
});
702+
703+
it(`${description}should render edge labels correctly when flowchart htmlLabels is false`, () => {
704+
imgSnapshotTest(
705+
`
706+
requirementDiagram
707+
requirement test_req {
708+
id: 1
709+
text: the test text.
710+
risk: high
711+
verifymethod: test
712+
}
713+
714+
functionalRequirement test_req2 {
715+
id: 1.1
716+
text: the second test text.
717+
risk: low
718+
verifymethod: inspection
719+
}
720+
721+
element test_entity {
722+
type: simulation
723+
}
724+
725+
element test_entity2 {
726+
type: word doc
727+
docRef: reqs/test_entity
728+
}
729+
730+
test_entity - satisfies -> test_req2
731+
test_req - traces -> test_req2
732+
test_req - contains -> test_req2
733+
test_entity2 - verifies -> test_req
734+
test_req <- copies - test_entity2
735+
`,
736+
{ ...options, flowchart: { htmlLabels: false } }
737+
);
738+
});
702739
});
703740
});

packages/mermaid/src/diagrams/er/styles.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,16 @@ const getStyles = (options: FlowChartStyleOptions) =>
6868
stroke: ${options.lineColor} !important;
6969
stroke-width: 1;
7070
}
71+
72+
.edgeLabel {
73+
background-color: ${options.edgeLabelBackground};
74+
}
75+
.edgeLabel .label rect {
76+
fill: ${options.edgeLabelBackground};
77+
}
78+
.edgeLabel .label text {
79+
fill: ${options.textColor};
80+
}
7181
`;
7282

7383
export default getStyles;

packages/mermaid/src/diagrams/requirement/requirementDb.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -321,7 +321,7 @@ export class RequirementDB implements DiagramDB {
321321
id: `${relation.src}-${relation.dst}-${counter}`,
322322
start: this.requirements.get(relation.src)?.name ?? this.elements.get(relation.src)?.name,
323323
end: this.requirements.get(relation.dst)?.name ?? this.elements.get(relation.dst)?.name,
324-
label: `&lt;&lt;${relation.type}&gt;&gt;`,
324+
label: `«${relation.type}»`,
325325
classes: 'relationshipLine',
326326
style: ['fill:none', isContains ? '' : 'stroke-dasharray: 10,7'],
327327
labelpos: 'c',

packages/mermaid/src/diagrams/requirement/styles.js

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,15 @@ const getStyles = (options) => `
4040
.relationshipLabel {
4141
fill: ${options.relationLabelColor};
4242
}
43+
.edgeLabel {
44+
background-color: ${options.edgeLabelBackground};
45+
}
46+
.edgeLabel .label rect {
47+
fill: ${options.edgeLabelBackground};
48+
}
49+
.edgeLabel .label text {
50+
fill: ${options.relationLabelColor};
51+
}
4352
.divider {
4453
stroke: ${options.nodeBorder};
4554
stroke-width: 1;

0 commit comments

Comments
 (0)