diff --git a/client/src/data/collab.rs b/client/src/data/collab.rs index e53b301..890140e 100644 --- a/client/src/data/collab.rs +++ b/client/src/data/collab.rs @@ -1,3 +1,4 @@ +use super::Side; use std::sync::{Arc, Mutex}; use uuid::Uuid; use yrs::updates::decoder::Decode; @@ -13,11 +14,6 @@ pub struct CollabGraph { pub y_order: ArrayRef, } -#[derive(Copy, Clone)] -pub enum Side { - Left, - Right, -} impl From for Any { fn from(side: Side) -> Self { match side { diff --git a/client/src/data/common.rs b/client/src/data/common.rs new file mode 100644 index 0000000..a00bd89 --- /dev/null +++ b/client/src/data/common.rs @@ -0,0 +1,14 @@ +#[derive(Copy, PartialEq, Clone, Debug)] +pub enum Side { + Left, + Right, +} + +#[derive(Clone, Copy, PartialEq, Eq, Debug)] +pub enum RelativeLocation { + Top, + Bottom, + Left, + Right, + Center, +} diff --git a/client/src/data/graph.rs b/client/src/data/graph.rs index b43e69f..8be08ac 100644 --- a/client/src/data/graph.rs +++ b/client/src/data/graph.rs @@ -1,11 +1,9 @@ -use crate::data::{CollabGraph, RelativeLocation, RenderedNode}; -use crate::data::{Node, NodeKind, NodeProperty}; +use super::{CollabGraph, Node, NodeKind, NodeProperty, RelativeLocation, RenderedNode, Side}; use dioxus::prelude::*; use std::collections::{HashMap, HashSet}; use std::sync::{Arc, Mutex}; use uuid::Uuid; -use super::collab::Side; use super::DEFAULT_COLOR; const SPACING_X: f32 = 50.0; // horizontal gap between parent and child @@ -103,29 +101,20 @@ impl Graph { None, node.text, node.color, + None, + node.estimate, + node.progress, + ), + NodeKind::Child { parent_id, side } => RenderedNode::new( + id, + (0.0, 0f32), + Some(parent_id), + node.text, + node.color, + Some(side), node.estimate, node.progress, ), - NodeKind::Child { parent_id, side } => { - let offset = match side { - Side::Left => -1f32, - _ => 1f32, - }; - let x = nodes - .read() - .get(&parent_id) - .map(|p| p.x + offset) - .unwrap_or(0f32); - RenderedNode::new( - id, - (x, 0f32), - Some(parent_id), - node.text, - node.color, - node.estimate, - node.progress, - ) - } }; nodes.write().insert(id, node); } else { @@ -475,7 +464,6 @@ impl UpdatedGraph { if children.is_empty() { return; } - if let Some(parent) = self.get_node(parent_id) { let total_height: f32 = children.iter().map(|id| heights[id]).sum::() + SPACING_Y * (children.len() as f32 - 1.0); @@ -502,17 +490,13 @@ impl UpdatedGraph { } fn assign_positions(&mut self, root_id: Uuid, heights: &HashMap) { - if let Some(root) = self.get_node(root_id) { - let root_x = root.x; + let children = self.direct_children(root_id); - let children = self.direct_children(root_id); + let (left, right): (Vec<_>, Vec<_>) = children + .into_iter() + .partition(|&id| self.get_node(id).unwrap().side.unwrap() == Side::Left); - let (left, right): (Vec<_>, Vec<_>) = children - .into_iter() - .partition(|&id| self.get_node(id).unwrap().x < root_x); - - self.spread_children_vertically(root_id, &left, heights, -1.0); - self.spread_children_vertically(root_id, &right, heights, 1.0); - } + self.spread_children_vertically(root_id, &left, heights, -1.0); + self.spread_children_vertically(root_id, &right, heights, 1.0); } } diff --git a/client/src/data/mod.rs b/client/src/data/mod.rs index 1b1ba27..bd72d10 100644 --- a/client/src/data/mod.rs +++ b/client/src/data/mod.rs @@ -1,5 +1,8 @@ +pub mod common; +pub use common::RelativeLocation; +pub use common::Side; + pub mod node; -pub use node::RelativeLocation; pub use node::RenderedNode; pub mod graph; diff --git a/client/src/data/node.rs b/client/src/data/node.rs index 10b8c84..7b8366e 100644 --- a/client/src/data/node.rs +++ b/client/src/data/node.rs @@ -1,4 +1,4 @@ -use super::{DEFAULT_COLOR, FONT_SIZE, TEXT_PADDING}; +use super::{RelativeLocation, Side, DEFAULT_COLOR, FONT_SIZE, TEXT_PADDING}; use std::sync::OnceLock; use uuid::Uuid; @@ -28,15 +28,6 @@ pub fn measure_line_height() -> f32 { .ceil() } -#[derive(Clone, Copy, PartialEq, Eq, Debug)] -pub enum RelativeLocation { - Top, - Bottom, - Left, - Right, - Center, -} - #[derive(Clone, PartialEq, Debug)] pub struct RenderedNode { pub id: Uuid, @@ -45,6 +36,7 @@ pub struct RenderedNode { pub text: String, pub parent_id: Option, pub color: Option, + pub side: Option, pub rendered_color: String, pub estimate: Option, pub estimate_rollup: f64, @@ -58,6 +50,7 @@ impl RenderedNode { parent_id: Option, text: String, color: Option, + side: Option, estimate: Option, progress: i64, ) -> Self { @@ -70,6 +63,7 @@ impl RenderedNode { color, estimate, progress, + side, estimate_rollup: 0.0, rendered_color: DEFAULT_COLOR.to_string(), } @@ -135,6 +129,7 @@ mod tests { text.to_string(), None, None, + None, 0, ) }