@@ -589,6 +589,8 @@ public void AutoLayout()
589589
590590 var dfsScope = nodes . ToDictionary ( k => k , v => 0 ) ;
591591
592+ var emptyNodes = new List < FluxoLayoutTree > ( ) ;
593+
592594 var pos = new Point ( this . ViewportLocation . X + 160d , this . ViewportLocation . Y + 100d ) ;
593595
594596 var hashTree = new Dictionary < int , List < FluxoLayoutTree > > ( ) ;
@@ -608,6 +610,8 @@ void Sorting()
608610 BuildHash ( tree , 0 ) ;
609611
610612 Hierarchy ( tree , pos ) ;
613+
614+ EmptyReLayout ( ) ;
611615 }
612616
613617 void Hierarchy ( FluxoLayoutTree root , Point position )
@@ -642,6 +646,36 @@ void Translate(FluxoLayoutTree node, Point location)
642646 }
643647 }
644648
649+ void EmptyReLayout ( )
650+ {
651+ foreach ( var emptyNode in emptyNodes )
652+ {
653+ var sources = emptyNode . Node . Lines
654+ . Where ( x => emptyNode . Node . NodeId . Equals ( x . TargetId ) )
655+ . Select ( x => x . Source )
656+ . OrderByDescending ( x => x ? . Location . X ) ;
657+
658+ var maxX = sources . FirstOrDefault ( ) ;
659+
660+ var x = maxX != null && maxX . Location . X + maxX . ActualWidth + span > emptyNode . Node . Location . X
661+ ? maxX . Location . X + maxX . ActualWidth + span
662+ : emptyNode . Node . Location . X ;
663+
664+ var y = ( sources . FirstOrDefault ( ) ? . Location . Y + sources . LastOrDefault ( ) ? . Location . Y +
665+ sources . LastOrDefault ( ) ? . ActualHeight ) / 2 ?? emptyNode . Node . Location . Y ;
666+
667+ emptyNode . Node . Location = new Point ( x , y ) ;
668+
669+ for ( var i = 0 ; i < emptyNode . Nexts . Count ; i ++ )
670+ {
671+ if ( ! emptyNode . Nexts [ i ] . Node . IsEmpty )
672+ {
673+ Hierarchy ( emptyNode . Nexts [ i ] , new Point ( x + span , y + i * span ) ) ;
674+ }
675+ }
676+ }
677+ }
678+
645679 void BuildHash ( FluxoLayoutTree root , int depth )
646680 {
647681 if ( hashTree . TryGetValue ( depth , out var value ) )
@@ -664,6 +698,11 @@ FluxoLayoutTree BuildTree(FluxoNode root, int depth)
664698 Depth = depth
665699 } ;
666700
701+ if ( root . IsEmpty )
702+ {
703+ emptyNodes . Add ( tree ) ;
704+ }
705+
667706 dfsScope [ root ] = 1 ;
668707
669708 var nexts = root . Lines . Where ( x => root . NodeId . Equals ( x . SourceId ) ) . Select ( x => x . Target ) ;
0 commit comments