Detect detached connections and render them differently
This commit is contained in:
parent
ebe0f5cfc0
commit
f1965f7530
4 changed files with 30 additions and 15 deletions
|
|
@ -48,28 +48,32 @@ pub fn populate_graph() -> Graph {
|
|||
let mut new_nodes: HashMap<String, Node> = HashMap::new();
|
||||
let mut incoming: HashMap<String, Vec<Edge>> = HashMap::new();
|
||||
|
||||
// If an edge has no "from" ID, default to its node's ID
|
||||
for (key, node) in graph.nodes.iter() {
|
||||
|
||||
let mut new_node = node.clone();
|
||||
let connections = node.connections.clone().unwrap_or_default();
|
||||
let mut vec = connections.clone();
|
||||
|
||||
for (i, edge) in connections.iter().enumerate() {
|
||||
|
||||
let mut new_edge = edge.clone();
|
||||
|
||||
if edge.from == "" {
|
||||
let new_edge = Edge {
|
||||
from: key.to_string(),
|
||||
..edge.clone()
|
||||
};
|
||||
let mut vec = connections.clone();
|
||||
vec[i] = new_edge;
|
||||
new_node = Node {
|
||||
connections: Some(vec),
|
||||
..node.clone()
|
||||
};
|
||||
new_edge.from = key.to_string();
|
||||
}
|
||||
|
||||
if ! graph.nodes.contains_key(&edge.to) {
|
||||
new_edge.detached = true;
|
||||
}
|
||||
|
||||
vec[i] = new_edge;
|
||||
|
||||
}
|
||||
|
||||
new_nodes.insert(key.to_string(), new_node.clone());
|
||||
let new_node = Node {
|
||||
connections: Some(vec),
|
||||
..node.clone()
|
||||
};
|
||||
new_nodes.insert(key.to_string(), new_node);
|
||||
}
|
||||
|
||||
// Construct a HashMap with incoming connections (reversed edges)
|
||||
|
|
|
|||
|
|
@ -12,11 +12,13 @@ pub struct Graph {
|
|||
|
||||
#[derive(Serialize, Clone, Default, PartialEq, Deserialize)]
|
||||
pub struct Edge {
|
||||
pub to: String,
|
||||
#[serde(default)]
|
||||
pub anchor: String,
|
||||
#[serde(default)]
|
||||
pub from: String,
|
||||
pub to: String,
|
||||
#[serde(default)]
|
||||
pub detached: bool,
|
||||
}
|
||||
|
||||
#[derive(Serialize, Deserialize, Clone, Default)]
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue