diff --git a/src/rsprocess/graph.rs b/src/rsprocess/graph.rs index e2de6fc..d0836f4 100644 --- a/src/rsprocess/graph.rs +++ b/src/rsprocess/graph.rs @@ -142,10 +142,22 @@ impl From<(Vec, Rc)> for GraphMapNodesTy impl GraphMapNodesTy { pub fn generate<'a>( - &self + self ) -> Box String + 'a> { - todo!() + let mut accumulator: + Box String + 'a> = + super::format_helpers::graph_map_nodes_ty_from::format_hide( + Rc::clone(&self.translator) + ); + for f in self.functions { + accumulator = Box::new(move |i, n| { + (accumulator)(i, n) + + &f(i, n) + }) + } + + accumulator } } @@ -155,6 +167,7 @@ impl GraphMapNodesTy { /// Helper structure that specifies what information to display for edges #[derive(Clone)] pub enum GraphMapEdges { + String { string: String }, Hide, Products, MaskProducts { mask: RSset }, @@ -176,7 +189,8 @@ type GraphMapEdgesFnTy = dyn Fn(petgraph::prelude::EdgeIndex, &RSlabel) -> Strin /// Helper structure that holds a formatting function from node as RSsystem to /// string pub struct GraphMapEdgesTy { - function: Box + function: Vec>, + translator: Rc } impl GraphMapEdgesTy { @@ -194,6 +208,9 @@ impl GraphMapEdgesTy { // borrow to the struct, also translator needs to be in box, a reference // is not enough match f { + String { string } => { + format_string(translator, string) + } Hide => { format_hide(translator) }, @@ -249,7 +266,7 @@ impl GraphMapEdgesTy { } // ----------------------------------------------------------------------------- -// Formatting Nodes & Edges +// Color Nodes & Edges // ----------------------------------------------------------------------------- use petgraph::visit::{IntoEdgeReferences, IntoNodeReferences}; diff --git a/src/rsprocess/presets.rs b/src/rsprocess/presets.rs index e24495c..3427d5c 100644 --- a/src/rsprocess/presets.rs +++ b/src/rsprocess/presets.rs @@ -561,7 +561,7 @@ pub fn bisimilar( // ----------------------------------------------------------------------------- #[allow(clippy::type_complexity)] -fn generate_node_pringting_fn<'a>( +fn generate_node_printing_fn<'a>( node_display: &[NodeDisplay], graph: &graph::RSgraph, translator: Rc, @@ -594,13 +594,15 @@ fn generate_node_pringting_fn<'a>( } ).collect::>(); - let gmnt = graph::GraphMapNodesTy::from((node_display, Rc::clone(&translator))); + let gmnt = graph::GraphMapNodesTy::from( + (node_display, Rc::clone(&translator)) + ); gmnt.generate() } #[allow(clippy::type_complexity)] -fn generate_edge_pringting_fn<'a>( +fn generate_edge_printing_fn<'a>( edge_display: &'a Vec, translator: Rc, ) -> Box String + 'a> { @@ -707,10 +709,10 @@ pub fn dot( // this is awful but rust is not a functional language so its all // fine... let modified_graph = graph.map( - generate_node_pringting_fn(&node_display, + generate_node_printing_fn(&node_display, graph, Rc::clone(&rc_translator)), - generate_edge_pringting_fn(&edge_display, + generate_edge_printing_fn(&edge_display, Rc::clone(&rc_translator)), ); @@ -751,10 +753,10 @@ pub fn graphml( // map each value to the corresponding value we want to display let modified_graph = graph.map( - generate_node_pringting_fn(&node_display, + generate_node_printing_fn(&node_display, graph, Rc::clone(&rc_translator)), - generate_edge_pringting_fn(&edge_display, + generate_edge_printing_fn(&edge_display, rc_translator), );