mirror of
https://github.com/mermaid-js/mermaid.git
synced 2025-01-28 07:03:17 +08:00
feat(er): allow multi-line relationship labels
This commit is contained in:
parent
87b2084d97
commit
261aea3089
@ -125,6 +125,35 @@
|
|||||||
</pre>
|
</pre>
|
||||||
<hr />
|
<hr />
|
||||||
|
|
||||||
|
<pre class="mermaid">
|
||||||
|
erDiagram
|
||||||
|
p[Person] {
|
||||||
|
string firstName
|
||||||
|
string lastName
|
||||||
|
}
|
||||||
|
a["Customer Account"] {
|
||||||
|
string email
|
||||||
|
}
|
||||||
|
|
||||||
|
b["Customer Account Secondary"] {
|
||||||
|
string email
|
||||||
|
}
|
||||||
|
|
||||||
|
c["Customer Account Tertiary"] {
|
||||||
|
string email
|
||||||
|
}
|
||||||
|
|
||||||
|
d["Customer Account Nth"] {
|
||||||
|
string email
|
||||||
|
}
|
||||||
|
|
||||||
|
p ||--o| a : "has<br />one"
|
||||||
|
p ||--o| b : "has<br />one<br />two"
|
||||||
|
p ||--o| c : "has<br />one<br />two<br />three"
|
||||||
|
p ||--o| d : "has<br />one<br />two<br />three<br />...<br />Nth"
|
||||||
|
</pre>
|
||||||
|
<hr />
|
||||||
|
|
||||||
<pre class="mermaid">
|
<pre class="mermaid">
|
||||||
erDiagram
|
erDiagram
|
||||||
_customer_order {
|
_customer_order {
|
||||||
|
@ -286,6 +286,7 @@ erDiagram
|
|||||||
|
|
||||||
- If you want the relationship label to be more than one word, you must use double quotes around the phrase
|
- If you want the relationship label to be more than one word, you must use double quotes around the phrase
|
||||||
- If you don't want a label at all on a relationship, you must use an empty double-quoted string
|
- If you don't want a label at all on a relationship, you must use an empty double-quoted string
|
||||||
|
- If you want a multi-line label on a relationship, use `<br />` between the two lines (`"first line<br />second line"`)
|
||||||
|
|
||||||
## Styling
|
## Styling
|
||||||
|
|
||||||
|
@ -519,6 +519,8 @@ const drawRelationshipFromLayout = function (svg, rel, g, insert, diagObj) {
|
|||||||
// Append a text node containing the label
|
// Append a text node containing the label
|
||||||
const labelId = 'rel' + relCnt;
|
const labelId = 'rel' + relCnt;
|
||||||
|
|
||||||
|
const labelText = rel.roleA.split(/<br ?\/>/g);
|
||||||
|
|
||||||
const labelNode = svg
|
const labelNode = svg
|
||||||
.append('text')
|
.append('text')
|
||||||
.classed('er relationshipLabel', true)
|
.classed('er relationshipLabel', true)
|
||||||
@ -528,8 +530,20 @@ const drawRelationshipFromLayout = function (svg, rel, g, insert, diagObj) {
|
|||||||
.style('text-anchor', 'middle')
|
.style('text-anchor', 'middle')
|
||||||
.style('dominant-baseline', 'middle')
|
.style('dominant-baseline', 'middle')
|
||||||
.style('font-family', getConfig().fontFamily)
|
.style('font-family', getConfig().fontFamily)
|
||||||
.style('font-size', conf.fontSize + 'px')
|
.style('font-size', conf.fontSize + 'px');
|
||||||
.text(rel.roleA);
|
|
||||||
|
if (labelText.length == 1) {
|
||||||
|
labelNode.text(rel.roleA);
|
||||||
|
} else {
|
||||||
|
const firstShift = -(labelText.length - 1) * 0.5;
|
||||||
|
labelText.forEach((txt, i) => {
|
||||||
|
labelNode
|
||||||
|
.append('tspan')
|
||||||
|
.attr('x', labelPoint.x)
|
||||||
|
.attr('dy', `${i === 0 ? firstShift : 1}em`)
|
||||||
|
.text(txt);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
// Figure out how big the opaque 'container' rectangle needs to be
|
// Figure out how big the opaque 'container' rectangle needs to be
|
||||||
const labelBBox = labelNode.node().getBBox();
|
const labelBBox = labelNode.node().getBBox();
|
||||||
|
@ -192,6 +192,7 @@ erDiagram
|
|||||||
|
|
||||||
- If you want the relationship label to be more than one word, you must use double quotes around the phrase
|
- If you want the relationship label to be more than one word, you must use double quotes around the phrase
|
||||||
- If you don't want a label at all on a relationship, you must use an empty double-quoted string
|
- If you don't want a label at all on a relationship, you must use an empty double-quoted string
|
||||||
|
- If you want a multi-line label on a relationship, use `<br />` between the two lines (`"first line<br />second line"`)
|
||||||
|
|
||||||
## Styling
|
## Styling
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user