Skip to content

Commit cc0a055

Browse files
committed
fix label length on lines layout
1 parent b060477 commit cc0a055

File tree

1 file changed

+23
-2
lines changed

1 file changed

+23
-2
lines changed

src/features/autoLayout/layouter.ts

Lines changed: 23 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import ElkConstructor, { ElkExtendedEdge, ElkNode } from "elkjs/lib/elk.bundled";
1+
import ElkConstructor, { ElkExtendedEdge, ElkLabel, ElkNode } from "elkjs/lib/elk.bundled";
22
import { injectable, inject } from "inversify";
33
import {
44
DefaultLayoutConfigurator,
@@ -9,10 +9,11 @@ import {
99
ILayoutPostprocessor,
1010
} from "sprotty-elk";
1111
import { SChildElementImpl, SShapeElementImpl, isBoundsAware } from "sprotty";
12-
import { SShapeElement, SModelIndex, SEdge } from "sprotty-protocol";
12+
import { SShapeElement, SModelIndex, SEdge, SLabel } from "sprotty-protocol";
1313
import { ElkShape, LayoutOptions } from "elkjs";
1414
import { SettingsManager } from "../settingsMenu/SettingsManager";
1515
import { LayoutMethod } from "../settingsMenu/LayoutMethod";
16+
import { calculateTextSize } from "../../utils";
1617

1718
export class DfdLayoutConfigurator extends DefaultLayoutConfigurator {
1819
constructor(@inject(SettingsManager) protected readonly settings: SettingsManager) {
@@ -104,6 +105,17 @@ export class DfdElkLayoutEngine extends ElkLayoutEngine {
104105
return elkEdge;
105106
}
106107

108+
protected override transformLabel(slabel: SLabel, index: SModelIndex): ElkLabel {
109+
const e = super.transformLabel(slabel, index);
110+
if (this.settings.layoutMethod === LayoutMethod.WRAPPING) {
111+
return e;
112+
}
113+
const size = calculateTextSize(slabel.text ?? "");
114+
e.height = size.height;
115+
e.width = size.width;
116+
return e;
117+
}
118+
107119
protected override applyShape(sshape: SShapeElement, elkShape: ElkShape, index: SModelIndex): void {
108120
// Check if this is a port, if yes we want to center it on the node edge instead of putting it right next to the node at the edge
109121
if (this.getBasicType(sshape) === "port") {
@@ -155,6 +167,15 @@ export class DfdElkLayoutEngine extends ElkLayoutEngine {
155167
}
156168

157169
super.applyShape(sshape, elkShape, index);
170+
171+
const parent = index.getParent(sshape.id);
172+
const parentType = parent ? this.getBasicType(parent) : "unknown";
173+
if (this.getBasicType(sshape) === "label" && parentType == "edge") {
174+
sshape.size = {
175+
width: -1,
176+
height: -1,
177+
};
178+
}
158179
}
159180

160181
protected applyEdge(sedge: SEdge, elkEdge: ElkExtendedEdge, index: SModelIndex): void {

0 commit comments

Comments
 (0)