1- use crate :: data:: { CollabGraph , RelativeLocation , RenderedNode } ;
2- use crate :: data:: { Node , NodeKind , NodeProperty } ;
1+ use super :: { CollabGraph , Node , NodeKind , NodeProperty , RelativeLocation , RenderedNode , Side } ;
32use dioxus:: prelude:: * ;
43use std:: collections:: { HashMap , HashSet } ;
54use std:: sync:: { Arc , Mutex } ;
65use uuid:: Uuid ;
76
8- use super :: collab:: Side ;
97use super :: DEFAULT_COLOR ;
108
119const SPACING_X : f32 = 50.0 ; // horizontal gap between parent and child
@@ -103,29 +101,20 @@ impl Graph {
103101 None ,
104102 node. text ,
105103 node. color ,
104+ None ,
105+ node. estimate ,
106+ node. progress ,
107+ ) ,
108+ NodeKind :: Child { parent_id, side } => RenderedNode :: new (
109+ id,
110+ ( 0.0 , 0f32 ) ,
111+ Some ( parent_id) ,
112+ node. text ,
113+ node. color ,
114+ Some ( side) ,
106115 node. estimate ,
107116 node. progress ,
108117 ) ,
109- NodeKind :: Child { parent_id, side } => {
110- let offset = match side {
111- Side :: Left => -1f32 ,
112- _ => 1f32 ,
113- } ;
114- let x = nodes
115- . read ( )
116- . get ( & parent_id)
117- . map ( |p| p. x + offset)
118- . unwrap_or ( 0f32 ) ;
119- RenderedNode :: new (
120- id,
121- ( x, 0f32 ) ,
122- Some ( parent_id) ,
123- node. text ,
124- node. color ,
125- node. estimate ,
126- node. progress ,
127- )
128- }
129118 } ;
130119 nodes. write ( ) . insert ( id, node) ;
131120 } else {
@@ -475,7 +464,6 @@ impl UpdatedGraph {
475464 if children. is_empty ( ) {
476465 return ;
477466 }
478-
479467 if let Some ( parent) = self . get_node ( parent_id) {
480468 let total_height: f32 = children. iter ( ) . map ( |id| heights[ id] ) . sum :: < f32 > ( )
481469 + SPACING_Y * ( children. len ( ) as f32 - 1.0 ) ;
@@ -502,17 +490,13 @@ impl UpdatedGraph {
502490 }
503491
504492 fn assign_positions ( & mut self , root_id : Uuid , heights : & HashMap < Uuid , f32 > ) {
505- if let Some ( root) = self . get_node ( root_id) {
506- let root_x = root. x ;
493+ let children = self . direct_children ( root_id) ;
507494
508- let children = self . direct_children ( root_id) ;
495+ let ( left, right) : ( Vec < _ > , Vec < _ > ) = children
496+ . into_iter ( )
497+ . partition ( |& id| self . get_node ( id) . unwrap ( ) . side . unwrap ( ) == Side :: Left ) ;
509498
510- let ( left, right) : ( Vec < _ > , Vec < _ > ) = children
511- . into_iter ( )
512- . partition ( |& id| self . get_node ( id) . unwrap ( ) . x < root_x) ;
513-
514- self . spread_children_vertically ( root_id, & left, heights, -1.0 ) ;
515- self . spread_children_vertically ( root_id, & right, heights, 1.0 ) ;
516- }
499+ self . spread_children_vertically ( root_id, & left, heights, -1.0 ) ;
500+ self . spread_children_vertically ( root_id, & right, heights, 1.0 ) ;
517501 }
518502}
0 commit comments