1
- import ElkConstructor , { ElkExtendedEdge , ElkNode } from "elkjs/lib/elk.bundled" ;
1
+ import ElkConstructor , { ElkExtendedEdge , ElkLabel , ElkNode } from "elkjs/lib/elk.bundled" ;
2
2
import { injectable , inject } from "inversify" ;
3
3
import {
4
4
DefaultLayoutConfigurator ,
@@ -9,10 +9,11 @@ import {
9
9
ILayoutPostprocessor ,
10
10
} from "sprotty-elk" ;
11
11
import { SChildElementImpl , SShapeElementImpl , isBoundsAware } from "sprotty" ;
12
- import { SShapeElement , SModelIndex , SEdge } from "sprotty-protocol" ;
12
+ import { SShapeElement , SModelIndex , SEdge , SLabel } from "sprotty-protocol" ;
13
13
import { ElkShape , LayoutOptions } from "elkjs" ;
14
14
import { SettingsManager } from "../settingsMenu/SettingsManager" ;
15
15
import { LayoutMethod } from "../settingsMenu/LayoutMethod" ;
16
+ import { calculateTextSize } from "../../utils" ;
16
17
17
18
export class DfdLayoutConfigurator extends DefaultLayoutConfigurator {
18
19
constructor ( @inject ( SettingsManager ) protected readonly settings : SettingsManager ) {
@@ -104,6 +105,17 @@ export class DfdElkLayoutEngine extends ElkLayoutEngine {
104
105
return elkEdge ;
105
106
}
106
107
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
+
107
119
protected override applyShape ( sshape : SShapeElement , elkShape : ElkShape , index : SModelIndex ) : void {
108
120
// 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
109
121
if ( this . getBasicType ( sshape ) === "port" ) {
@@ -155,6 +167,15 @@ export class DfdElkLayoutEngine extends ElkLayoutEngine {
155
167
}
156
168
157
169
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
+ }
158
179
}
159
180
160
181
protected applyEdge ( sedge : SEdge , elkEdge : ElkExtendedEdge , index : SModelIndex ) : void {
0 commit comments