Make edge modulation steps more consistent

This commit is contained in:
Juno Takano 2026-01-12 14:34:55 -03:00
commit bd5d46a5d4
8 changed files with 227 additions and 118 deletions

View file

@ -4,8 +4,6 @@ use serde::{Serialize, Deserialize};
pub struct Edge {
pub to: String,
#[serde(default)]
pub anchor: String,
#[serde(default)]
pub from: String,
#[serde(default)]
pub detached: bool,

View file

@ -1,3 +1,5 @@
use std::collections::HashMap;
use serde::{Serialize, Deserialize};
use super::edge::Edge;
@ -20,7 +22,7 @@ pub struct Node {
pub hidden: bool,
#[serde(skip_serializing_if = "Option::is_none")]
pub connections: Option<Vec<Edge>>,
pub connections: Option<HashMap<String, Edge>>,
}
impl Node {
@ -41,6 +43,40 @@ impl Node {
}
}
impl std::fmt::Display for Node {
fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
let mut meta = String::default();
if self.title.is_empty() {
meta.push_str("title:none");
} else {
meta.push_str(&format!("title:'{}'", self.title));
}
if self.text.is_empty() {
meta.push_str(" text:none");
} else {
meta.push_str(&format!(" text:{}l", self.text.len()));
}
if self.summary.is_empty() {
meta.push_str(" summary:none");
} else {
meta.push_str(&format!(" summary:{}", self.summary.len()));
}
if self.redirect.is_empty() {
meta.push_str(" redirect:none");
} else {
meta.push_str(&format!(" redirect:{}", self.redirect));
}
let links = self.links.len();
if links > 0 {
meta.push_str(&format!(" links:{links}"));
}
if self.hidden {
meta.push_str(" hidden");
}
write!(f, "Node: ID '{}' {meta}", self.id)
}
}
#[cfg(test)]
mod tests {
use super::*;