Make edge modulation steps more consistent
This commit is contained in:
parent
db8c02df04
commit
bd5d46a5d4
8 changed files with 227 additions and 118 deletions
|
|
@ -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,
|
||||
|
|
|
|||
|
|
@ -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::*;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue