diff --git a/src/formats.rs b/src/formats.rs index 99cf409..3e434c5 100644 --- a/src/formats.rs +++ b/src/formats.rs @@ -48,28 +48,32 @@ pub fn populate_graph() -> Graph { let mut new_nodes: HashMap = HashMap::new(); let mut incoming: HashMap> = 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) diff --git a/src/types.rs b/src/types.rs index 18b8d53..a865e65 100644 --- a/src/types.rs +++ b/src/types.rs @@ -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)] diff --git a/templates/node.html b/templates/node.html index 71f341c..277a517 100644 --- a/templates/node.html +++ b/templates/node.html @@ -16,13 +16,20 @@

Connections

{% if connections %} {% else %} No outgoing connections. diff --git a/templates/tree.html b/templates/tree.html index 8ba6b7f..15866d0 100644 --- a/templates/tree.html +++ b/templates/tree.html @@ -60,7 +60,9 @@
  • Connections
      {% for connection in node.connections %} + {% if not connection.detached %}
    • {{connection.to}}
    • + {% endif %} {% endfor %}