@@ -28,18 +28,26 @@ const rootLayoutOptions = {
2828// the number of pixels of padding between nodes and between nodes and their parents
2929const nodePadding = 5 ;
3030
31- const classLayoutOptions = {
32- "elk.algorithm" : "layered" ,
33- "elk.direction" : "DOWN" ,
34- "elk.spacing.componentComponent" : nodePadding . toString ( ) ,
35- "elk.spacing.nodeNode" : nodePadding . toString ( ) ,
36- "elk.padding" : `[top=${ nodePadding } ,left=${ nodePadding } ,bottom=${ nodePadding } ,right=${ nodePadding } ]` ,
37- "elk.spacing.portPort" : "0" ,
38- // allow ports on e-class to be anywhere
39- // TODO: they only seem to appear on top side of nodes, figure out if there is a way to allow them
40- // to be on all sides if it would result in a better layout
41- portConstraints : "FREE" ,
42- } ;
31+ /// amount of padding per extra class item
32+ const extra_padding = 8 ;
33+ function classLayoutOptions ( n_extra : number ) {
34+ let top = nodePadding + n_extra * extra_padding ;
35+ if ( n_extra > 0 ) {
36+ top += 2 ;
37+ }
38+ return {
39+ "elk.algorithm" : "layered" ,
40+ "elk.direction" : "DOWN" ,
41+ "elk.spacing.componentComponent" : nodePadding . toString ( ) ,
42+ "elk.spacing.nodeNode" : nodePadding . toString ( ) ,
43+ "elk.padding" : `[top=${ top } ,left=${ nodePadding } ,bottom=${ nodePadding } ,right=${ nodePadding } ]` ,
44+ "elk.spacing.portPort" : "0" ,
45+ // allow ports on e-class to be anywhere
46+ // TODO: they only seem to appear on top side of nodes, figure out if there is a way to allow them
47+ // to be on all sides if it would result in a better layout
48+ portConstraints : "FREE" ,
49+ } ;
50+ }
4351
4452// https://github.com/eclipse/elk/issues/1037#issuecomment-2122136560
4553const interactiveOptions = {
@@ -83,6 +91,7 @@ export type FlowClass = Node<
8391 {
8492 color : string | null ;
8593 id : string ;
94+ extra : { [ key : string ] : string } ;
8695 // selected?: boolean
8796 } ,
8897 "class"
@@ -275,10 +284,11 @@ function toELKNode(
275284 elkRoot . layoutOptions ! [ "elk.aspectRatio" ] = aspectRatio as unknown as string ;
276285 for ( const [ classID , nodes ] of classToNodes . entries ( ) ) {
277286 const elkClassID = `class-${ classID } ` ;
287+ const extra = class_data [ classID ] ? Object . fromEntries ( Object . entries ( class_data [ classID ] ! ) . filter ( ( [ key ] ) => key !== "type" ) ) : { } ;
278288 const elkClass : MyELKNode [ "children" ] [ 0 ] = {
279289 id : elkClassID ,
280- data : { color : colors . get ( class_data [ classID ] ?. type ) ! , id : classID } ,
281- layoutOptions : classLayoutOptions ,
290+ data : { color : colors . get ( class_data [ classID ] ?. type ) ! , id : classID , extra } ,
291+ layoutOptions : classLayoutOptions ( Object . keys ( extra ) . length ) ,
282292 children : [ ] ,
283293 ports : mergeEdges
284294 ? [ ]
0 commit comments