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)]
|
||||
|
|
|
|||
|
|
@ -16,13 +16,20 @@
|
|||
<h2>Connections</h2>
|
||||
{% if connections %}
|
||||
<ul>
|
||||
{% for connection in connections %}
|
||||
{% for connection in connections | filter(attribute="detached", value=false) %}
|
||||
<li>
|
||||
<strong>{{id}}</strong>
|
||||
🡪
|
||||
<a href="/node/{{connection.to}}">{{connection.to}}</a>
|
||||
</li>
|
||||
{% endfor %}
|
||||
{% for connection in connections | filter(attribute="detached", value=true) %}
|
||||
<li>
|
||||
<strong>{{id}}</strong>
|
||||
🡪
|
||||
<span style="filter: opacity(70%);">{{connection.to}}</span>
|
||||
</li>
|
||||
{% endfor %}
|
||||
</ul>
|
||||
{% else %}
|
||||
<em>No outgoing connections.</em>
|
||||
|
|
|
|||
|
|
@ -60,7 +60,9 @@
|
|||
<li><strong>Connections</strong>
|
||||
<ul>
|
||||
{% for connection in node.connections %}
|
||||
{% if not connection.detached %}
|
||||
<li><a href="/node/{{connection.to}}">{{connection.to}}</a></li>
|
||||
{% endif %}
|
||||
{% endfor %}
|
||||
</ul>
|
||||
</li>
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue