1- import ElkConstructor , { ElkExtendedEdge , ElkNode } from "elkjs/lib/elk.bundled" ;
1+ import ElkConstructor , { ElkExtendedEdge , ElkLabel , ElkNode } from "elkjs/lib/elk.bundled" ;
22import { injectable , inject } from "inversify" ;
33import {
44 DefaultLayoutConfigurator ,
@@ -9,10 +9,11 @@ import {
99 ILayoutPostprocessor ,
1010} from "sprotty-elk" ;
1111import { SChildElementImpl , SShapeElementImpl , isBoundsAware } from "sprotty" ;
12- import { SShapeElement , SModelIndex , SEdge } from "sprotty-protocol" ;
12+ import { SShapeElement , SModelIndex , SEdge , SLabel } from "sprotty-protocol" ;
1313import { ElkShape , LayoutOptions } from "elkjs" ;
1414import { SettingsManager } from "../settingsMenu/SettingsManager" ;
1515import { LayoutMethod } from "../settingsMenu/LayoutMethod" ;
16+ import { calculateTextSize } from "../../utils" ;
1617
1718export 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