Skip to content

Commit 83ee510

Browse files
Fix init layout bug
1 parent bf85348 commit 83ee510

File tree

5 files changed

+42
-50
lines changed

5 files changed

+42
-50
lines changed

client/src/data/collab.rs

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
use super::Side;
12
use std::sync::{Arc, Mutex};
23
use uuid::Uuid;
34
use yrs::updates::decoder::Decode;
@@ -13,11 +14,6 @@ pub struct CollabGraph {
1314
pub y_order: ArrayRef,
1415
}
1516

16-
#[derive(Copy, Clone)]
17-
pub enum Side {
18-
Left,
19-
Right,
20-
}
2117
impl From<Side> for Any {
2218
fn from(side: Side) -> Self {
2319
match side {

client/src/data/common.rs

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
#[derive(Copy, PartialEq, Clone, Debug)]
2+
pub enum Side {
3+
Left,
4+
Right,
5+
}
6+
7+
#[derive(Clone, Copy, PartialEq, Eq, Debug)]
8+
pub enum RelativeLocation {
9+
Top,
10+
Bottom,
11+
Left,
12+
Right,
13+
Center,
14+
}

client/src/data/graph.rs

Lines changed: 18 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,9 @@
1-
use crate::data::{CollabGraph, RelativeLocation, RenderedNode};
2-
use crate::data::{Node, NodeKind, NodeProperty};
1+
use super::{CollabGraph, Node, NodeKind, NodeProperty, RelativeLocation, RenderedNode, Side};
32
use dioxus::prelude::*;
43
use std::collections::{HashMap, HashSet};
54
use std::sync::{Arc, Mutex};
65
use uuid::Uuid;
76

8-
use super::collab::Side;
97
use super::DEFAULT_COLOR;
108

119
const 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
}

client/src/data/mod.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
1+
pub mod common;
2+
pub use common::RelativeLocation;
3+
pub use common::Side;
4+
15
pub mod node;
2-
pub use node::RelativeLocation;
36
pub use node::RenderedNode;
47

58
pub mod graph;

client/src/data/node.rs

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
use super::{DEFAULT_COLOR, FONT_SIZE, TEXT_PADDING};
1+
use super::{RelativeLocation, Side, DEFAULT_COLOR, FONT_SIZE, TEXT_PADDING};
22
use std::sync::OnceLock;
33
use uuid::Uuid;
44

@@ -28,15 +28,6 @@ pub fn measure_line_height() -> f32 {
2828
.ceil()
2929
}
3030

31-
#[derive(Clone, Copy, PartialEq, Eq, Debug)]
32-
pub enum RelativeLocation {
33-
Top,
34-
Bottom,
35-
Left,
36-
Right,
37-
Center,
38-
}
39-
4031
#[derive(Clone, PartialEq, Debug)]
4132
pub struct RenderedNode {
4233
pub id: Uuid,
@@ -45,6 +36,7 @@ pub struct RenderedNode {
4536
pub text: String,
4637
pub parent_id: Option<Uuid>,
4738
pub color: Option<String>,
39+
pub side: Option<Side>,
4840
pub rendered_color: String,
4941
pub estimate: Option<f64>,
5042
pub estimate_rollup: f64,
@@ -58,6 +50,7 @@ impl RenderedNode {
5850
parent_id: Option<Uuid>,
5951
text: String,
6052
color: Option<String>,
53+
side: Option<Side>,
6154
estimate: Option<f64>,
6255
progress: i64,
6356
) -> Self {
@@ -70,6 +63,7 @@ impl RenderedNode {
7063
color,
7164
estimate,
7265
progress,
66+
side,
7367
estimate_rollup: 0.0,
7468
rendered_color: DEFAULT_COLOR.to_string(),
7569
}
@@ -135,6 +129,7 @@ mod tests {
135129
text.to_string(),
136130
None,
137131
None,
132+
None,
138133
0,
139134
)
140135
}

0 commit comments

Comments
 (0)