Fix for interface rendering and positioning

This commit is contained in:
Ashish Jain
2020-08-13 20:08:09 +02:00
parent 36f8f1902c
commit bec3cc437d
2 changed files with 8 additions and 6 deletions

View File

@@ -54,6 +54,8 @@
Customer "1" --> "*" Ticket Customer "1" --> "*" Ticket
Student "1" --> "1..*" Course Student "1" --> "1..*" Course
Galaxy --> "many" Star : Contains Galaxy --> "many" Star : Contains
<<interface>> Customer
<<Service>> Galaxy
</div> </div>
<script src="./mermaid.js"></script> <script src="./mermaid.js"></script>
<script> <script>

View File

@@ -568,9 +568,12 @@ const class_box = (parent, node) => {
const hasInterface = node.classData.annotations && node.classData.annotations[0]; const hasInterface = node.classData.annotations && node.classData.annotations[0];
// 1. Create the labels // 1. Create the labels
const interfaceLabelText = node.classData.annotations[0]
? '<<' + node.classData.annotations[0] + '>>'
: '';
const interfaceLabel = labelContainer const interfaceLabel = labelContainer
.node() .node()
.appendChild(createLabel(node.classData.annotations[0], node.labelStyle, true, true)); .appendChild(createLabel(interfaceLabelText, node.labelStyle, true, true));
const interfaceBBox = interfaceLabel.getBBox(); const interfaceBBox = interfaceLabel.getBBox();
if (node.classData.annotations[0]) { if (node.classData.annotations[0]) {
maxHeight += interfaceBBox.height + rowPadding; maxHeight += interfaceBBox.height + rowPadding;
@@ -614,13 +617,10 @@ const class_box = (parent, node) => {
// position the interface label // position the interface label
if (hasInterface) { if (hasInterface) {
let diffX = (maxWidth - interfaceBBox.width) / 2;
select(interfaceLabel).attr( select(interfaceLabel).attr(
'transform', 'transform',
'translate( ' + 'translate( ' + ((-1 * maxWidth) / 2 + diffX) + ', ' + (-1 * maxHeight) / 2 + ')'
-(maxWidth + node.padding - interfaceBBox.width / 2) / 2 +
', ' +
(-1 * maxHeight) / 2 +
')'
); );
verticalPos = interfaceBBox.height + rowPadding; verticalPos = interfaceBBox.height + rowPadding;
} }