Refactoring

This commit is contained in:
elvis
2025-07-26 20:01:46 +02:00
parent cf071e4c76
commit f6428f7f36
2 changed files with 30 additions and 11 deletions

View File

@ -142,10 +142,22 @@ impl From<(Vec<GraphMapNodes>, Rc<translator::Translator>)> for GraphMapNodesTy
impl GraphMapNodesTy { impl GraphMapNodesTy {
pub fn generate<'a>( pub fn generate<'a>(
&self self
) -> Box<dyn Fn(petgraph::prelude::NodeIndex, &'a RSsystem) -> String + 'a> ) -> Box<dyn Fn(petgraph::prelude::NodeIndex, &'a RSsystem) -> String + 'a>
{ {
todo!() let mut accumulator:
Box<dyn Fn(petgraph::prelude::NodeIndex, &'a RSsystem) -> 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 /// Helper structure that specifies what information to display for edges
#[derive(Clone)] #[derive(Clone)]
pub enum GraphMapEdges { pub enum GraphMapEdges {
String { string: String },
Hide, Hide,
Products, Products,
MaskProducts { mask: RSset }, 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 /// Helper structure that holds a formatting function from node as RSsystem to
/// string /// string
pub struct GraphMapEdgesTy { pub struct GraphMapEdgesTy {
function: Box<GraphMapEdgesFnTy> function: Vec<Box<GraphMapEdgesFnTy>>,
translator: Rc<translator::Translator>
} }
impl GraphMapEdgesTy { impl GraphMapEdgesTy {
@ -194,6 +208,9 @@ impl GraphMapEdgesTy {
// borrow to the struct, also translator needs to be in box, a reference // borrow to the struct, also translator needs to be in box, a reference
// is not enough // is not enough
match f { match f {
String { string } => {
format_string(translator, string)
}
Hide => { Hide => {
format_hide(translator) format_hide(translator)
}, },
@ -249,7 +266,7 @@ impl GraphMapEdgesTy {
} }
// ----------------------------------------------------------------------------- // -----------------------------------------------------------------------------
// Formatting Nodes & Edges // Color Nodes & Edges
// ----------------------------------------------------------------------------- // -----------------------------------------------------------------------------
use petgraph::visit::{IntoEdgeReferences, IntoNodeReferences}; use petgraph::visit::{IntoEdgeReferences, IntoNodeReferences};

View File

@ -561,7 +561,7 @@ pub fn bisimilar(
// ----------------------------------------------------------------------------- // -----------------------------------------------------------------------------
#[allow(clippy::type_complexity)] #[allow(clippy::type_complexity)]
fn generate_node_pringting_fn<'a>( fn generate_node_printing_fn<'a>(
node_display: &[NodeDisplay], node_display: &[NodeDisplay],
graph: &graph::RSgraph, graph: &graph::RSgraph,
translator: Rc<Translator>, translator: Rc<Translator>,
@ -594,13 +594,15 @@ fn generate_node_pringting_fn<'a>(
} }
).collect::<Vec<_>>(); ).collect::<Vec<_>>();
let gmnt = graph::GraphMapNodesTy::from((node_display, Rc::clone(&translator))); let gmnt = graph::GraphMapNodesTy::from(
(node_display, Rc::clone(&translator))
);
gmnt.generate() gmnt.generate()
} }
#[allow(clippy::type_complexity)] #[allow(clippy::type_complexity)]
fn generate_edge_pringting_fn<'a>( fn generate_edge_printing_fn<'a>(
edge_display: &'a Vec<EdgeDisplay>, edge_display: &'a Vec<EdgeDisplay>,
translator: Rc<Translator>, translator: Rc<Translator>,
) -> Box<dyn Fn(petgraph::prelude::EdgeIndex, &'a RSlabel) -> String + 'a> { ) -> Box<dyn Fn(petgraph::prelude::EdgeIndex, &'a RSlabel) -> String + 'a> {
@ -707,10 +709,10 @@ pub fn dot(
// this is awful but rust is not a functional language so its all // this is awful but rust is not a functional language so its all
// fine... // fine...
let modified_graph = graph.map( let modified_graph = graph.map(
generate_node_pringting_fn(&node_display, generate_node_printing_fn(&node_display,
graph, graph,
Rc::clone(&rc_translator)), Rc::clone(&rc_translator)),
generate_edge_pringting_fn(&edge_display, generate_edge_printing_fn(&edge_display,
Rc::clone(&rc_translator)), Rc::clone(&rc_translator)),
); );
@ -751,10 +753,10 @@ pub fn graphml(
// map each value to the corresponding value we want to display // map each value to the corresponding value we want to display
let modified_graph = graph.map( let modified_graph = graph.map(
generate_node_pringting_fn(&node_display, generate_node_printing_fn(&node_display,
graph, graph,
Rc::clone(&rc_translator)), Rc::clone(&rc_translator)),
generate_edge_pringting_fn(&edge_display, generate_edge_printing_fn(&edge_display,
rc_translator), rc_translator),
); );