Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 1 addition & 5 deletions client/src/data/collab.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
use super::Side;
use std::sync::{Arc, Mutex};
use uuid::Uuid;
use yrs::updates::decoder::Decode;
Expand All @@ -13,11 +14,6 @@ pub struct CollabGraph {
pub y_order: ArrayRef,
}

#[derive(Copy, Clone)]
pub enum Side {
Left,
Right,
}
impl From<Side> for Any {
fn from(side: Side) -> Self {
match side {
Expand Down
14 changes: 14 additions & 0 deletions client/src/data/common.rs
Original file line number Diff line number Diff line change
@@ -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,
}
52 changes: 18 additions & 34 deletions client/src/data/graph.rs
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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::<f32>()
+ SPACING_Y * (children.len() as f32 - 1.0);
Expand All @@ -502,17 +490,13 @@ impl UpdatedGraph {
}

fn assign_positions(&mut self, root_id: Uuid, heights: &HashMap<Uuid, f32>) {
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);
}
}
5 changes: 4 additions & 1 deletion client/src/data/mod.rs
Original file line number Diff line number Diff line change
@@ -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;
Expand Down
15 changes: 5 additions & 10 deletions client/src/data/node.rs
Original file line number Diff line number Diff line change
@@ -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;

Expand Down Expand Up @@ -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,
Expand All @@ -45,6 +36,7 @@ pub struct RenderedNode {
pub text: String,
pub parent_id: Option<Uuid>,
pub color: Option<String>,
pub side: Option<Side>,
pub rendered_color: String,
pub estimate: Option<f64>,
pub estimate_rollup: f64,
Expand All @@ -58,6 +50,7 @@ impl RenderedNode {
parent_id: Option<Uuid>,
text: String,
color: Option<String>,
side: Option<Side>,
estimate: Option<f64>,
progress: i64,
) -> Self {
Expand All @@ -70,6 +63,7 @@ impl RenderedNode {
color,
estimate,
progress,
side,
estimate_rollup: 0.0,
rendered_color: DEFAULT_COLOR.to_string(),
}
Expand Down Expand Up @@ -135,6 +129,7 @@ mod tests {
text.to_string(),
None,
None,
None,
0,
)
}
Expand Down