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 new_nodes: HashMap<String, Node> = HashMap::new();
|
||||||
let mut incoming: HashMap<String, Vec<Edge>> = 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() {
|
for (key, node) in graph.nodes.iter() {
|
||||||
|
|
||||||
let mut new_node = node.clone();
|
|
||||||
let connections = node.connections.clone().unwrap_or_default();
|
let connections = node.connections.clone().unwrap_or_default();
|
||||||
|
let mut vec = connections.clone();
|
||||||
|
|
||||||
for (i, edge) in connections.iter().enumerate() {
|
for (i, edge) in connections.iter().enumerate() {
|
||||||
|
|
||||||
|
let mut new_edge = edge.clone();
|
||||||
|
|
||||||
if edge.from == "" {
|
if edge.from == "" {
|
||||||
let new_edge = Edge {
|
new_edge.from = key.to_string();
|
||||||
from: key.to_string(),
|
|
||||||
..edge.clone()
|
|
||||||
};
|
|
||||||
let mut vec = connections.clone();
|
|
||||||
vec[i] = new_edge;
|
|
||||||
new_node = Node {
|
|
||||||
connections: Some(vec),
|
|
||||||
..node.clone()
|
|
||||||
};
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
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)
|
// Construct a HashMap with incoming connections (reversed edges)
|
||||||
|
|
|
||||||
|
|
@ -12,11 +12,13 @@ pub struct Graph {
|
||||||
|
|
||||||
#[derive(Serialize, Clone, Default, PartialEq, Deserialize)]
|
#[derive(Serialize, Clone, Default, PartialEq, Deserialize)]
|
||||||
pub struct Edge {
|
pub struct Edge {
|
||||||
|
pub to: String,
|
||||||
#[serde(default)]
|
#[serde(default)]
|
||||||
pub anchor: String,
|
pub anchor: String,
|
||||||
#[serde(default)]
|
#[serde(default)]
|
||||||
pub from: String,
|
pub from: String,
|
||||||
pub to: String,
|
#[serde(default)]
|
||||||
|
pub detached: bool,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Serialize, Deserialize, Clone, Default)]
|
#[derive(Serialize, Deserialize, Clone, Default)]
|
||||||
|
|
|
||||||
|
|
@ -16,13 +16,20 @@
|
||||||
<h2>Connections</h2>
|
<h2>Connections</h2>
|
||||||
{% if connections %}
|
{% if connections %}
|
||||||
<ul>
|
<ul>
|
||||||
{% for connection in connections %}
|
{% for connection in connections | filter(attribute="detached", value=false) %}
|
||||||
<li>
|
<li>
|
||||||
<strong>{{id}}</strong>
|
<strong>{{id}}</strong>
|
||||||
🡪
|
🡪
|
||||||
<a href="/node/{{connection.to}}">{{connection.to}}</a>
|
<a href="/node/{{connection.to}}">{{connection.to}}</a>
|
||||||
</li>
|
</li>
|
||||||
{% endfor %}
|
{% 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>
|
</ul>
|
||||||
{% else %}
|
{% else %}
|
||||||
<em>No outgoing connections.</em>
|
<em>No outgoing connections.</em>
|
||||||
|
|
|
||||||
|
|
@ -60,7 +60,9 @@
|
||||||
<li><strong>Connections</strong>
|
<li><strong>Connections</strong>
|
||||||
<ul>
|
<ul>
|
||||||
{% for connection in node.connections %}
|
{% for connection in node.connections %}
|
||||||
|
{% if not connection.detached %}
|
||||||
<li><a href="/node/{{connection.to}}">{{connection.to}}</a></li>
|
<li><a href="/node/{{connection.to}}">{{connection.to}}</a></li>
|
||||||
|
{% endif %}
|
||||||
{% endfor %}
|
{% endfor %}
|
||||||
</ul>
|
</ul>
|
||||||
</li>
|
</li>
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue